diff --git a/test/assertions.js b/test/assertions.js index facce83d9..11c11be90 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -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); +}); diff --git a/test/integration/api/odata.js b/test/integration/api/odata.js index 56b258811..ff785686c 100644 --- a/test/integration/api/odata.js +++ b/test/integration/api/odata.js @@ -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) => @@ -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' }); }) ])))))); @@ -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 @@ -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' }); }); })); @@ -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) => @@ -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) => { @@ -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']; }); @@ -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']; }); diff --git a/test/unit/formats/odata.js b/test/unit/formats/odata.js index b00efbb2c..5cb8ccbe5 100644 --- a/test/unit/formats/odata.js +++ b/test/unit/formats/odata.js @@ -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(); }))); }); @@ -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(); }))); }); @@ -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: [{ @@ -763,6 +766,7 @@ describe('odata message composition', () => { age: 6 }] }); + parsed['@odata.nextLink'].should.have.skiptoken({ repeatId: 'c76d0ccc6d5da236be7b93b985a80413d2e3e172' }); done(); }))); }); @@ -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: [{ @@ -815,6 +820,7 @@ describe('odata message composition', () => { age: 6 }] }); + parsed['@odata.nextLink'].should.have.skiptoken({ repeatId: 'c76d0ccc6d5da236be7b93b985a80413d2e3e172' }); done(); }))); }); @@ -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' }); }); }); });