Skip to content

Commit 7b7deff

Browse files
authored
Enhance/dataset assertions (getodk#787)
* remove identity function from the login call in the tests * added to.be.dataset assertions
1 parent 9db0d79 commit 7b7deff

File tree

6 files changed

+69
-53
lines changed

6 files changed

+69
-53
lines changed

test/assertions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,23 @@ should.Assertion.add('eqlInAnyOrder', function(expectedUnsorted) {
343343
const expectedSorted = [ ...expectedUnsorted ].sort();
344344
actualSorted.should.eql(expectedSorted);
345345
});
346+
347+
should.Assertion.add('Dataset', function assertDataset() {
348+
this.params = { operator: 'to be a Dataset' };
349+
350+
Object.keys(this.obj).should.containDeep([ 'projectId', 'name', 'createdAt' ]);
351+
this.obj.projectId.should.be.a.Number();
352+
this.obj.name.should.be.a.String();
353+
this.obj.createdAt.should.be.an.isoDate();
354+
});
355+
356+
should.Assertion.add('ExtendedDataset', function assertExtendedDataset() {
357+
this.params = { operator: 'to be an extended Dataset' };
358+
359+
Object.keys(this.obj).should.containDeep([ 'projectId', 'name', 'createdAt', 'entities', 'lastEntity' ]);
360+
this.obj.projectId.should.be.a.Number();
361+
this.obj.name.should.be.a.String();
362+
this.obj.createdAt.should.be.an.isoDate();
363+
this.obj.entities.should.be.a.Number();
364+
if (this.obj.lastEntity != null) this.obj.lastEntity.should.be.an.isoDate();
365+
});

test/integration/api/datasets.js

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const testData = require('../../data/xml');
44
const config = require('config');
55
const { Form } = require('../../../lib/model/frames');
66
const { getOrNotFound } = require('../../../lib/util/promise');
7-
const { omit, identity } = require('ramda');
7+
const { omit } = require('ramda');
88
const should = require('should');
99
const { sql } = require('slonik');
1010

@@ -36,13 +36,14 @@ describe('datasets and entities', () => {
3636
asAlice.get('/v1/projects/1/datasets')
3737
.expect(200)
3838
.then(({ body }) => {
39+
body[0].should.be.a.Dataset();
3940
body.map(({ createdAt, ...d }) => d).should.eql([
4041
{ name: 'people', projectId: 1 }
4142
]);
4243
})))));
4344

4445
it('should return the extended datasets of Default project', testService(async (service, container) => {
45-
const asAlice = await service.login('alice', identity);
46+
const asAlice = await service.login('alice');
4647

4748
await asAlice.post('/v1/projects/1/forms?publish=true')
4849
.send(testData.forms.simpleEntity)
@@ -64,11 +65,8 @@ describe('datasets and entities', () => {
6465
.set('X-Extended-Metadata', 'true')
6566
.expect(200)
6667
.then(({ body }) => {
67-
body.map(({ createdAt, lastEntity, ...d }) => {
68-
createdAt.should.not.be.null();
69-
lastEntity.should.not.be.null();
70-
return d;
71-
}).should.eql([
68+
body[0].should.be.an.ExtendedDataset();
69+
body.map(({ createdAt, lastEntity, ...d }) => d).should.eql([
7270
{ name: 'people', projectId: 1, entities: 1 }
7371
]);
7472
});
@@ -89,6 +87,7 @@ describe('datasets and entities', () => {
8987
asAlice.get('/v1/projects/1/datasets')
9088
.expect(200)
9189
.then(({ body }) => {
90+
body[0].should.be.a.Dataset();
9291
body.map(({ id, createdAt, ...d }) => d).should.eql([
9392
{ name: 'student', projectId: 1 }
9493
]);
@@ -98,7 +97,7 @@ describe('datasets and entities', () => {
9897
describe('projects/:id/datasets GET extended', () => {
9998

10099
it('should return the 0 for entities', testService(async (service) => {
101-
const asAlice = await service.login('alice', identity);
100+
const asAlice = await service.login('alice');
102101

103102
await asAlice.post('/v1/projects/1/forms?publish=true')
104103
.send(testData.forms.simpleEntity)
@@ -109,8 +108,8 @@ describe('datasets and entities', () => {
109108
.set('X-Extended-Metadata', 'true')
110109
.expect(200)
111110
.then(({ body }) => {
111+
body[0].should.be.an.ExtendedDataset();
112112
body.map(({ createdAt, lastEntity, ...d }) => {
113-
createdAt.should.not.be.null();
114113
should(lastEntity).be.null();
115114
return d;
116115
}).should.eql([
@@ -120,7 +119,7 @@ describe('datasets and entities', () => {
120119
}));
121120

122121
it('should return the extended datasets of Default project', testService(async (service, container) => {
123-
const asAlice = await service.login('alice', identity);
122+
const asAlice = await service.login('alice');
124123

125124
await asAlice.post('/v1/projects/1/forms?publish=true')
126125
.send(testData.forms.simpleEntity)
@@ -142,6 +141,7 @@ describe('datasets and entities', () => {
142141
.set('X-Extended-Metadata', 'true')
143142
.expect(200)
144143
.then(({ body }) => {
144+
body[0].should.be.an.ExtendedDataset();
145145
body.map(({ createdAt, lastEntity, ...d }) => {
146146
createdAt.should.not.be.null();
147147
lastEntity.should.not.be.null();
@@ -153,7 +153,7 @@ describe('datasets and entities', () => {
153153
}));
154154

155155
it('should return the correct count and latest timestamp of entities', testService(async (service, container) => {
156-
const asAlice = await service.login('alice', identity);
156+
const asAlice = await service.login('alice');
157157

158158
await asAlice.post('/v1/projects/1/forms?publish=true')
159159
.send(testData.forms.simpleEntity)
@@ -188,9 +188,8 @@ describe('datasets and entities', () => {
188188
.set('X-Extended-Metadata', 'true')
189189
.expect(200)
190190
.then(({ body }) => {
191+
body[0].should.be.an.ExtendedDataset();
191192
body.map(({ createdAt, lastEntity, ...d }) => {
192-
createdAt.should.not.be.null();
193-
lastEntity.should.not.be.null();
194193
lastEntity.should.not.startWith('1999');
195194
return d;
196195
}).should.eql([
@@ -200,7 +199,7 @@ describe('datasets and entities', () => {
200199
}));
201200

202201
it('should return the correct count for multiple dataset', testService(async (service, container) => {
203-
const asAlice = await service.login('alice', identity);
202+
const asAlice = await service.login('alice');
204203

205204
// Create Datasets
206205
await asAlice.post('/v1/projects/1/forms?publish=true')
@@ -288,7 +287,7 @@ describe('datasets and entities', () => {
288287
})))));
289288

290289
it('should return only published properties', testService(async (service) => {
291-
const asAlice = await service.login('alice', identity);
290+
const asAlice = await service.login('alice');
292291

293292
await asAlice.post('/v1/projects/1/forms?publish=true')
294293
.send(testData.forms.simpleEntity)
@@ -397,7 +396,7 @@ describe('datasets and entities', () => {
397396
describe('projects/:id/datasets/:name GET', () => {
398397

399398
it('should return the metadata of the dataset', testService(async (service) => {
400-
const asAlice = await service.login('alice', identity);
399+
const asAlice = await service.login('alice');
401400

402401
await asAlice.post('/v1/projects/1/forms?publish=true')
403402
.send(testData.forms.simpleEntity)
@@ -451,7 +450,7 @@ describe('datasets and entities', () => {
451450
}));
452451

453452
it('should not return duplicate linkedForms', testService(async (service) => {
454-
const asAlice = await service.login('alice', identity);
453+
const asAlice = await service.login('alice');
455454

456455
await asAlice.post('/v1/projects/1/forms?publish=true')
457456
.send(testData.forms.simpleEntity)
@@ -482,7 +481,7 @@ describe('datasets and entities', () => {
482481
}));
483482

484483
it('should return properties of a dataset in order', testService(async (service) => {
485-
const asAlice = await service.login('alice', identity);
484+
const asAlice = await service.login('alice');
486485

487486
await asAlice.post('/v1/projects/1/forms?publish=true')
488487
.send(testData.forms.multiPropertyEntity)
@@ -504,7 +503,7 @@ describe('datasets and entities', () => {
504503
}));
505504

506505
it('should return dataset properties from multiple forms in order', testService(async (service) => {
507-
const asAlice = await service.login('alice', identity);
506+
const asAlice = await service.login('alice');
508507

509508
await asAlice.post('/v1/projects/1/forms?publish=true')
510509
.send(testData.forms.multiPropertyEntity)
@@ -536,7 +535,7 @@ describe('datasets and entities', () => {
536535
}));
537536

538537
it('should return dataset properties from multiple forms including updated form with updated schema', testService(async (service) => {
539-
const asAlice = await service.login('alice', identity);
538+
const asAlice = await service.login('alice');
540539

541540
await asAlice.post('/v1/projects/1/forms?publish=true')
542541
.send(testData.forms.multiPropertyEntity)
@@ -578,7 +577,7 @@ describe('datasets and entities', () => {
578577
}));
579578

580579
it('should return dataset properties when purged draft form shares some properties', testService(async (service, { Forms }) => {
581-
const asAlice = await service.login('alice', identity);
580+
const asAlice = await service.login('alice');
582581

583582
await asAlice.post('/v1/projects/1/forms')
584583
.send(testData.forms.multiPropertyEntity)
@@ -613,7 +612,7 @@ describe('datasets and entities', () => {
613612
}));
614613

615614
it('should return dataset properties when draft form (purged before second form publish) shares some properties', testService(async (service, { Forms }) => {
616-
const asAlice = await service.login('alice', identity);
615+
const asAlice = await service.login('alice');
617616

618617
await asAlice.post('/v1/projects/1/forms')
619618
.send(testData.forms.multiPropertyEntity)
@@ -650,7 +649,7 @@ describe('datasets and entities', () => {
650649
}));
651650

652651
it.skip('should return ordered dataset properties including from deleted published form', testService(async (service, { Forms }) => {
653-
const asAlice = await service.login('alice', identity);
652+
const asAlice = await service.login('alice');
654653

655654
await asAlice.post('/v1/projects/1/forms?publish=true')
656655
.send(testData.forms.multiPropertyEntity)
@@ -947,7 +946,7 @@ describe('datasets and entities', () => {
947946
})))));
948947

949948
it('should return error if dataset is not published', testService(async (service) => {
950-
const asAlice = await service.login('alice', identity);
949+
const asAlice = await service.login('alice');
951950

952951
await asAlice.post('/v1/projects/1/forms')
953952
.send(testData.forms.withAttachments)
@@ -1323,7 +1322,7 @@ describe('datasets and entities', () => {
13231322
}])))))));
13241323

13251324
it('should return inForm false for removed property', testService(async (service) => {
1326-
const asAlice = await service.login('alice', identity);
1325+
const asAlice = await service.login('alice');
13271326

13281327
await asAlice.post('/v1/projects/1/forms?publish=true')
13291328
.set('Content-Type', 'application/xml')
@@ -1354,7 +1353,7 @@ describe('datasets and entities', () => {
13541353

13551354
it('should return empty array if managed encryption is enabled', testService(async (service) => {
13561355
// Upload a form and then create a new draft version
1357-
const asAlice = await service.login('alice', identity);
1356+
const asAlice = await service.login('alice');
13581357

13591358
await asAlice.post('/v1/projects/1/forms')
13601359
.send(testData.forms.simpleEntity)
@@ -1374,7 +1373,7 @@ describe('datasets and entities', () => {
13741373

13751374
it('should return empty array if form is encrypted', testService(async (service) => {
13761375
// Upload a form and then create a new draft version
1377-
const asAlice = await service.login('alice', identity);
1376+
const asAlice = await service.login('alice');
13781377

13791378
await asAlice.post('/v1/projects/1/forms')
13801379
.send(testData.forms.simpleEntity.replace('</model>', '<submission base64RsaPublicKey="abc"/></model>'))
@@ -1461,7 +1460,7 @@ describe('datasets and entities', () => {
14611460
}));
14621461

14631462
it('should return dataset name only if there is no properties', testService(async (service) => {
1464-
const asAlice = await service.login('alice', identity);
1463+
const asAlice = await service.login('alice');
14651464

14661465
await asAlice.post('/v1/projects/1/forms?publish=true')
14671466
.send(testData.forms.simpleEntity.replace(/entities:saveto[^/]+/g, ''))
@@ -1480,7 +1479,7 @@ describe('datasets and entities', () => {
14801479
}));
14811480

14821481
it('should let the user download even if there are no properties', testService(async (service) => {
1483-
const asAlice = await service.login('alice', identity);
1482+
const asAlice = await service.login('alice');
14841483

14851484
await asAlice.post('/v1/projects/1/forms?publish=true')
14861485
.send(testData.forms.simpleEntity.replace(/entities:saveto[^/]+/g, ''))
@@ -1704,7 +1703,7 @@ describe('datasets and entities', () => {
17041703

17051704
it('should log dataset publishing in audit log', testService(async (service, { Audits }) => {
17061705

1707-
const asAlice = await service.login('alice', identity);
1706+
const asAlice = await service.login('alice');
17081707

17091708
await asAlice.post('/v1/projects/1/forms?publish=true')
17101709
.send(testData.forms.simpleEntity)
@@ -1735,7 +1734,7 @@ describe('datasets and entities', () => {
17351734

17361735
describe('dataset property interaction with intermediate form schemas and purging uneeded drafts', () => {
17371736
it('should clean up form fields and dataset properties of unneeded drafts', testService(async (service, container) => {
1738-
const asAlice = await service.login('alice', identity);
1737+
const asAlice = await service.login('alice');
17391738

17401739
await asAlice.post('/v1/projects/1/forms?publish=true')
17411740
.set('Content-Type', 'application/xml')
@@ -1770,7 +1769,7 @@ describe('datasets and entities', () => {
17701769

17711770
describe('dataset and entities should have isolated lifecycle', () => {
17721771
it('should allow a form that has created an entity to be purged', testService(async (service, container) => {
1773-
const asAlice = await service.login('alice', identity);
1772+
const asAlice = await service.login('alice');
17741773

17751774
await asAlice.post('/v1/projects/1/forms?publish=true')
17761775
.set('Content-Type', 'application/xml')
@@ -1819,7 +1818,7 @@ describe('datasets and entities', () => {
18191818
}));
18201819

18211820
it('should return published dataset even if corresponding form is deleted', testService(async (service, container) => {
1822-
const asAlice = await service.login('alice', identity);
1821+
const asAlice = await service.login('alice');
18231822

18241823
await asAlice.post('/v1/projects/1/forms?publish=true')
18251824
.set('Content-Type', 'application/xml')
@@ -1839,7 +1838,7 @@ describe('datasets and entities', () => {
18391838
}));
18401839

18411840
it('should keep dataset and its property status intact even if corresponding form is deleted', testService(async (service, container) => {
1842-
const asAlice = await service.login('alice', identity);
1841+
const asAlice = await service.login('alice');
18431842

18441843
await asAlice.post('/v1/projects/1/forms?publish=true')
18451844
.set('Content-Type', 'application/xml')

test/integration/api/forms/forms.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const superagent = require('superagent');
77
const { DateTime } = require('luxon');
88
const { testService } = require('../../setup');
99
const testData = require('../../../data/xml');
10-
const { identity } = require('ramda');
1110
// eslint-disable-next-line import/no-dynamic-require
1211
const { exhaust } = require(appRoot + '/lib/worker/worker');
1312

@@ -354,7 +353,7 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
354353
})))));
355354

356355
it('should reject with deleted form exists warning', testService(async (service) => {
357-
const asAlice = await service.login('alice', identity);
356+
const asAlice = await service.login('alice');
358357

359358
await asAlice.delete('/v1/projects/1/forms/simple')
360359
.expect(200);
@@ -370,7 +369,7 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
370369
}));
371370

372371
it('should reject with xls and deleted form exists warnings', testService(async (service) => {
373-
const asAlice = await service.login('alice', identity);
372+
const asAlice = await service.login('alice');
374373

375374
await asAlice.post('/v1/projects/1/forms?publish=true')
376375
.send(testData.forms.simple2)
@@ -394,7 +393,7 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
394393
}));
395394

396395
it('should reject with structure changed warning', testService(async (service) => {
397-
const asAlice = await service.login('alice', identity);
396+
const asAlice = await service.login('alice');
398397

399398
await asAlice.post('/v1/projects/1/forms/simple/draft')
400399
.send(testData.forms.simple.replace(/age/g, 'address'))
@@ -406,7 +405,7 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
406405
}));
407406

408407
it('should reject with structure changed warning', testService(async (service) => {
409-
const asAlice = await service.login('alice', identity);
408+
const asAlice = await service.login('alice');
410409

411410
await asAlice.post('/v1/projects/1/forms/simple/draft?ignoreWarnings=true')
412411
.send(testData.forms.simple.replace(/age/g, 'address'))
@@ -418,7 +417,7 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
418417
}));
419418

420419
it('should reject with xls and structure changed warnings', testService(async (service) => {
421-
const asAlice = await service.login('alice', identity);
420+
const asAlice = await service.login('alice');
422421

423422
await asAlice.post('/v1/projects/1/forms?publish=true')
424423
.send(testData.forms.simple2.replace(/age/g, 'address'))
@@ -492,7 +491,7 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
492491
}));
493492

494493
it('should create the form for xml files with warnings given ignoreWarnings', testService(async (service) => {
495-
const asAlice = await service.login('alice', identity);
494+
const asAlice = await service.login('alice');
496495

497496
await asAlice.post('/v1/projects/1/forms?publish=true')
498497
.send(testData.forms.simple2)

0 commit comments

Comments
 (0)