Skip to content

Commit

Permalink
test/odata: de-obfuscate $skiptoken values in tests (#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Dec 3, 2024
1 parent 3d86d4b commit 71cd2b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions test/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,9 @@ should.Assertion.add('EntitySourceSubmissionDetails', function SubmissionDetails
this.obj.should.have.property('instanceId').which.is.a.String();
this.obj.should.have.property('instanceName'); // can be null
});

should.Assertion.add('skiptoken', function skiptoken(expected) {
this.params = { operator: 'to have a skiptoken' };

JSON.parse(Buffer.from(decodeURIComponent(new URL(this.obj).searchParams.get('$skiptoken').substr(2)), 'base64')).should.deepEqual(expected);
});
8 changes: 8 additions & 0 deletions test/integration/api/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ describe('api: /forms/:id.svc', () => {
}
}]
});
body['@odata.nextLink'].should.have.skiptoken({ repeatId: 'b6e93a81a53eed0566e65e472d4a4b9ae383ee6d' });
}))));

it('should return just a count if asked', testService((service) =>
Expand Down Expand Up @@ -401,6 +402,7 @@ describe('api: /forms/:id.svc', () => {
.expect(200)
.then(({ body }) => {
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');
body['@odata.nextLink'].should.have.skiptoken({ repeatId: '7ac5f4d4facbaa9657c21ff221b885241c284b6c' });
})
]))))));

Expand Down Expand Up @@ -835,6 +837,7 @@ describe('api: /forms/:id.svc', () => {
}
}]
});
body['@odata.nextLink'].should.have.skiptoken({ instanceId: 'rtwo' });
}))));

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

Expand Down Expand Up @@ -1093,6 +1097,7 @@ describe('api: /forms/:id.svc', () => {
}
}]
});
body['@odata.nextLink'].should.have.skiptoken({ instanceId: 'rthree' });
}))));

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

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

Expand All @@ -1893,6 +1900,7 @@ describe('api: /forms/:id.svc', () => {
.then(({ body }) => {
body.value[0].name.should.be.eql('Billy');
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');
body['@odata.nextLink'].should.have.skiptoken({ repeatId: '52eff9ea82550183880b9d64c20487642fa6e60c' });
return body['@odata.nextLink'];
});

Expand Down
11 changes: 9 additions & 2 deletions test/unit/formats/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ describe('odata message composition', () => {
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
const resultObj = JSON.parse(result);
resultObj['@odata.nextLink'].should.equal('http://localhost:8989/simple.svc/Submissions?%24top=3&%24skiptoken=01e30%3D');
resultObj['@odata.nextLink'].should.have.skiptoken({});
done();
})));
});
Expand All @@ -598,6 +599,7 @@ describe('odata message composition', () => {
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
const resultObj = JSON.parse(result);
resultObj['@odata.nextLink'].should.equal('http://localhost:8989/simple.svc/Submissions?%24top=3&%24wkt=true&%24count=true&%24skiptoken=01e30%3D');
resultObj['@odata.nextLink'].should.have.skiptoken({});
done();
})));
});
Expand Down Expand Up @@ -748,7 +750,8 @@ describe('odata message composition', () => {
fieldsFor(testData.forms.withrepeat)
.then((fields) => rowStreamToOData(fields, 'Submissions.children.child', 'http://localhost:8989', '/withrepeat.svc/Submissions.children.child?$top=2', query, inRows))
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
JSON.parse(result).should.eql({
const parsed = JSON.parse(result);
parsed.should.eql({
'@odata.context': 'http://localhost:8989/withrepeat.svc/$metadata#Submissions.children.child',
'@odata.nextLink': 'http://localhost:8989/withrepeat.svc/Submissions.children.child?%24top=2&%24skiptoken=01eyJyZXBlYXRJZCI6ImM3NmQwY2NjNmQ1ZGEyMzZiZTdiOTNiOTg1YTgwNDEzZDJlM2UxNzIifQ%3D%3D',
value: [{
Expand All @@ -763,6 +766,7 @@ describe('odata message composition', () => {
age: 6
}]
});
parsed['@odata.nextLink'].should.have.skiptoken({ repeatId: 'c76d0ccc6d5da236be7b93b985a80413d2e3e172' });
done();
})));
});
Expand Down Expand Up @@ -805,7 +809,8 @@ describe('odata message composition', () => {
fieldsFor(testData.forms.withrepeat)
.then((fields) => rowStreamToOData(fields, 'Submissions.children.child', 'http://localhost:8989', '/withrepeat.svc/Submissions.children.child?$skip=1&$top=1', query, inRows))
.then((stream) => stream.pipe(streamTest.toText((_, result) => {
JSON.parse(result).should.eql({
const parsed = JSON.parse(result);
parsed.should.eql({
'@odata.context': 'http://localhost:8989/withrepeat.svc/$metadata#Submissions.children.child',
'@odata.nextLink': 'http://localhost:8989/withrepeat.svc/Submissions.children.child?%24top=1&%24skiptoken=01eyJyZXBlYXRJZCI6ImM3NmQwY2NjNmQ1ZGEyMzZiZTdiOTNiOTg1YTgwNDEzZDJlM2UxNzIifQ%3D%3D',
value: [{
Expand All @@ -815,6 +820,7 @@ describe('odata message composition', () => {
age: 6
}]
});
parsed['@odata.nextLink'].should.have.skiptoken({ repeatId: 'c76d0ccc6d5da236be7b93b985a80413d2e3e172' });
done();
})));
});
Expand Down Expand Up @@ -1063,6 +1069,7 @@ describe('odata message composition', () => {
.then(JSON.parse)
.then((result) => {
result['@odata.nextLink'].should.equal("http://localhost:8989/withrepeat.svc/Submissions('two')/children/child?%24top=1&%24wkt=true&%24skiptoken=01eyJyZXBlYXRJZCI6ImNmOWExYjVjYzgzYzZkNjI3MGMxZWI5ODg2MGQyOTRlYWM1ZDUyNmQifQ%3D%3D");
result['@odata.nextLink'].should.have.skiptoken({ repeatId: 'cf9a1b5cc83c6d6270c1eb98860d294eac5d526d' });
});
});
});
Expand Down

0 comments on commit 71cd2b6

Please sign in to comment.