Skip to content

Commit 71cd2b6

Browse files
authored
test/odata: de-obfuscate $skiptoken values in tests (#1312)
1 parent 3d86d4b commit 71cd2b6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

test/assertions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,9 @@ should.Assertion.add('EntitySourceSubmissionDetails', function SubmissionDetails
444444
this.obj.should.have.property('instanceId').which.is.a.String();
445445
this.obj.should.have.property('instanceName'); // can be null
446446
});
447+
448+
should.Assertion.add('skiptoken', function skiptoken(expected) {
449+
this.params = { operator: 'to have a skiptoken' };
450+
451+
JSON.parse(Buffer.from(decodeURIComponent(new URL(this.obj).searchParams.get('$skiptoken').substr(2)), 'base64')).should.deepEqual(expected);
452+
});

test/integration/api/odata.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ describe('api: /forms/:id.svc', () => {
329329
}
330330
}]
331331
});
332+
body['@odata.nextLink'].should.have.skiptoken({ repeatId: 'b6e93a81a53eed0566e65e472d4a4b9ae383ee6d' });
332333
}))));
333334

334335
it('should return just a count if asked', testService((service) =>
@@ -401,6 +402,7 @@ describe('api: /forms/:id.svc', () => {
401402
.expect(200)
402403
.then(({ body }) => {
403404
body['@odata.nextLink'].should.equal('http://localhost:8989/v1/projects/1/forms/double%20repeat.svc/Submissions(%27uuid%3A17b09e96-4141-43f5-9a70-611eb0e8f6b4%27)/children/child?%24top=1&%24skiptoken=01eyJyZXBlYXRJZCI6IjdhYzVmNGQ0ZmFjYmFhOTY1N2MyMWZmMjIxYjg4NTI0MWMyODRiNmMifQ%3D%3D');
405+
body['@odata.nextLink'].should.have.skiptoken({ repeatId: '7ac5f4d4facbaa9657c21ff221b885241c284b6c' });
404406
})
405407
]))))));
406408

@@ -835,6 +837,7 @@ describe('api: /forms/:id.svc', () => {
835837
}
836838
}]
837839
});
840+
body['@odata.nextLink'].should.have.skiptoken({ instanceId: 'rtwo' });
838841
}))));
839842

840843
// nb: order of id and createdAt is not guaranteed to be same
@@ -1053,6 +1056,7 @@ describe('api: /forms/:id.svc', () => {
10531056
age: 38,
10541057
});
10551058
body['@odata.nextLink'].should.be.eql('http://localhost:8989/v1/projects/1/forms/withrepeat.svc/Submissions?%24top=1&%24select=age&%24skiptoken=01eyJpbnN0YW5jZUlkIjoicnRocmVlIn0%3D');
1059+
body['@odata.nextLink'].should.have.skiptoken({ instanceId: 'rthree' });
10561060
});
10571061
}));
10581062

@@ -1093,6 +1097,7 @@ describe('api: /forms/:id.svc', () => {
10931097
}
10941098
}]
10951099
});
1100+
body['@odata.nextLink'].should.have.skiptoken({ instanceId: 'rthree' });
10961101
}))));
10971102

10981103
it('should return submitter-filtered toplevel rows if requested', testService((service) =>
@@ -1785,6 +1790,7 @@ describe('api: /forms/:id.svc', () => {
17851790
age: 4
17861791
}]
17871792
});
1793+
body['@odata.nextLink'].should.have.skiptoken({ repeatId: '52eff9ea82550183880b9d64c20487642fa6e60c' });
17881794
}))));
17891795

17901796
it('should reject if subtable filtering criterion is non-root', testService(async (service) => {
@@ -1870,6 +1876,7 @@ describe('api: /forms/:id.svc', () => {
18701876
body.value[0].name.should.be.eql('Candace');
18711877
body.value[1].name.should.be.eql('Billy');
18721878
body['@odata.nextLink'].should.eql('http://localhost:8989/v1/projects/1/forms/withrepeat.svc/Submissions.children.child?%24top=2&%24skiptoken=01eyJyZXBlYXRJZCI6IjUyZWZmOWVhODI1NTAxODM4ODBiOWQ2NGMyMDQ4NzY0MmZhNmU2MGMifQ%3D%3D');
1879+
body['@odata.nextLink'].should.have.skiptoken({ repeatId: '52eff9ea82550183880b9d64c20487642fa6e60c' });
18731880
return body['@odata.nextLink'];
18741881
});
18751882

@@ -1893,6 +1900,7 @@ describe('api: /forms/:id.svc', () => {
18931900
.then(({ body }) => {
18941901
body.value[0].name.should.be.eql('Billy');
18951902
body['@odata.nextLink'].should.eql('http://localhost:8989/v1/projects/1/forms/withrepeat.svc/Submissions.children.child?%24top=1&%24filter=%24root%2FSubmissions%2F__system%2FreviewState+eq+%27rejected%27&%24skiptoken=01eyJyZXBlYXRJZCI6IjUyZWZmOWVhODI1NTAxODM4ODBiOWQ2NGMyMDQ4NzY0MmZhNmU2MGMifQ%3D%3D');
1903+
body['@odata.nextLink'].should.have.skiptoken({ repeatId: '52eff9ea82550183880b9d64c20487642fa6e60c' });
18961904
return body['@odata.nextLink'];
18971905
});
18981906

test/unit/formats/odata.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ describe('odata message composition', () => {
586586
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
587587
const resultObj = JSON.parse(result);
588588
resultObj['@odata.nextLink'].should.equal('http://localhost:8989/simple.svc/Submissions?%24top=3&%24skiptoken=01e30%3D');
589+
resultObj['@odata.nextLink'].should.have.skiptoken({});
589590
done();
590591
})));
591592
});
@@ -598,6 +599,7 @@ describe('odata message composition', () => {
598599
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
599600
const resultObj = JSON.parse(result);
600601
resultObj['@odata.nextLink'].should.equal('http://localhost:8989/simple.svc/Submissions?%24top=3&%24wkt=true&%24count=true&%24skiptoken=01e30%3D');
602+
resultObj['@odata.nextLink'].should.have.skiptoken({});
601603
done();
602604
})));
603605
});
@@ -748,7 +750,8 @@ describe('odata message composition', () => {
748750
fieldsFor(testData.forms.withrepeat)
749751
.then((fields) => rowStreamToOData(fields, 'Submissions.children.child', 'http://localhost:8989', '/withrepeat.svc/Submissions.children.child?$top=2', query, inRows))
750752
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
751-
JSON.parse(result).should.eql({
753+
const parsed = JSON.parse(result);
754+
parsed.should.eql({
752755
'@odata.context': 'http://localhost:8989/withrepeat.svc/$metadata#Submissions.children.child',
753756
'@odata.nextLink': 'http://localhost:8989/withrepeat.svc/Submissions.children.child?%24top=2&%24skiptoken=01eyJyZXBlYXRJZCI6ImM3NmQwY2NjNmQ1ZGEyMzZiZTdiOTNiOTg1YTgwNDEzZDJlM2UxNzIifQ%3D%3D',
754757
value: [{
@@ -763,6 +766,7 @@ describe('odata message composition', () => {
763766
age: 6
764767
}]
765768
});
769+
parsed['@odata.nextLink'].should.have.skiptoken({ repeatId: 'c76d0ccc6d5da236be7b93b985a80413d2e3e172' });
766770
done();
767771
})));
768772
});
@@ -805,7 +809,8 @@ describe('odata message composition', () => {
805809
fieldsFor(testData.forms.withrepeat)
806810
.then((fields) => rowStreamToOData(fields, 'Submissions.children.child', 'http://localhost:8989', '/withrepeat.svc/Submissions.children.child?$skip=1&$top=1', query, inRows))
807811
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
808-
JSON.parse(result).should.eql({
812+
const parsed = JSON.parse(result);
813+
parsed.should.eql({
809814
'@odata.context': 'http://localhost:8989/withrepeat.svc/$metadata#Submissions.children.child',
810815
'@odata.nextLink': 'http://localhost:8989/withrepeat.svc/Submissions.children.child?%24top=1&%24skiptoken=01eyJyZXBlYXRJZCI6ImM3NmQwY2NjNmQ1ZGEyMzZiZTdiOTNiOTg1YTgwNDEzZDJlM2UxNzIifQ%3D%3D',
811816
value: [{
@@ -815,6 +820,7 @@ describe('odata message composition', () => {
815820
age: 6
816821
}]
817822
});
823+
parsed['@odata.nextLink'].should.have.skiptoken({ repeatId: 'c76d0ccc6d5da236be7b93b985a80413d2e3e172' });
818824
done();
819825
})));
820826
});
@@ -1063,6 +1069,7 @@ describe('odata message composition', () => {
10631069
.then(JSON.parse)
10641070
.then((result) => {
10651071
result['@odata.nextLink'].should.equal("http://localhost:8989/withrepeat.svc/Submissions('two')/children/child?%24top=1&%24wkt=true&%24skiptoken=01eyJyZXBlYXRJZCI6ImNmOWExYjVjYzgzYzZkNjI3MGMxZWI5ODg2MGQyOTRlYWM1ZDUyNmQifQ%3D%3D");
1072+
result['@odata.nextLink'].should.have.skiptoken({ repeatId: 'cf9a1b5cc83c6d6270c1eb98860d294eac5d526d' });
10661073
});
10671074
});
10681075
});

0 commit comments

Comments
 (0)