Skip to content

Commit

Permalink
added test for extended datasets/:name
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Sep 1, 2023
1 parent 6a0a87e commit 7b59340
Showing 1 changed file with 64 additions and 15 deletions.
79 changes: 64 additions & 15 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ describe('datasets and entities', () => {
const withOutTs = result.replace(isoRegex, '');
withOutTs.should.be.eql(
'__id,label,first_name,age,__createdAt,__creatorId,__creatorName,__updates,__updatedAt\n' +
'12345678-1234-4123-8234-123456789aaa,Jane (30),Jane,30,,5,Alice,0,\n' +
'12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88,,5,Alice,0,\n'
'12345678-1234-4123-8234-123456789aaa,Jane (30),Jane,30,,5,Alice,0,\n' +
'12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88,,5,Alice,0,\n'
);

}));
Expand Down Expand Up @@ -399,7 +399,7 @@ describe('datasets and entities', () => {
const withOutTs = result.replace(isoRegex, '');
withOutTs.should.be.eql(
'__id,label,first_name,the.age,__createdAt,__creatorId,__creatorName,__updates,__updatedAt\n' +
'12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88,,5,Alice,0,\n'
'12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88,,5,Alice,0,\n'
);

}));
Expand Down Expand Up @@ -472,7 +472,7 @@ describe('datasets and entities', () => {
const withOutTs = result.replace(isoRegex, '');
withOutTs.should.be.eql(
'__id,label,first_name,age,__createdAt,__creatorId,__creatorName,__updates,__updatedAt\n' +
'12345678-1234-4123-8234-111111111aaa,Robert Doe (expired),Robert,,,5,Alice,1,\n'
'12345678-1234-4123-8234-111111111aaa,Robert Doe (expired),Robert,,,5,Alice,1,\n'
);

}));
Expand Down Expand Up @@ -555,18 +555,67 @@ describe('datasets and entities', () => {

sourceForms.should.be.eql([
{ name: 'simpleEntity', xmlFormId: 'simpleEntity' },
{ name: 'simpleEntity2', xmlFormId: 'simpleEntity2' } ]);
{ name: 'simpleEntity2', xmlFormId: 'simpleEntity2' }]);

properties.map(({ publishedAt, ...p }) => {
publishedAt.should.be.isoDate();
return p;
}).should.be.eql([
{
name: 'first_name', odataName: 'first_name', forms: [
{ name: 'simpleEntity', xmlFormId: 'simpleEntity' },
{ name: 'simpleEntity2', xmlFormId: 'simpleEntity2' }
]
},
{ name: 'the.age', odataName: 'the_age', forms: [{ name: 'simpleEntity', xmlFormId: 'simpleEntity' },] },
{ name: 'address', odataName: 'address', forms: [{ name: 'simpleEntity2', xmlFormId: 'simpleEntity2' },] }
]);

});

}));

it('should return the extended metadata of the dataset', testService(async (service) => {
const asAlice = await service.login('alice');

await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simpleEntity)
.set('Content-Type', 'application/xml')
.expect(200);

await asAlice.post('/v1/projects/1/datasets/people/entities')
.send({
uuid: '12345678-1234-4123-8234-111111111aaa',
label: 'Johnny Doe'
})
.expect(200);

await asAlice.get('/v1/projects/1/datasets/people')
.set('X-Extended-Metadata', 'true')
.expect(200)
.then(({ body }) => {

const { createdAt, properties, lastEntity, ...ds } = body;

ds.should.be.eql({
name: 'people',
projectId: 1,
approvalRequired: false,
entities: 1,
linkedForms: [],
sourceForms: [{ name: 'simpleEntity', xmlFormId: 'simpleEntity' }]
});

lastEntity.should.be.recentIsoDate();

createdAt.should.be.recentIsoDate();

properties.map(({ publishedAt, ...p }) => {
publishedAt.should.be.isoDate();
return p;
}).should.be.eql([
{ name: 'first_name', odataName: 'first_name', forms: [
{ name: 'simpleEntity', xmlFormId: 'simpleEntity' },
{ name: 'simpleEntity2', xmlFormId: 'simpleEntity2' }
] },
{ name: 'the.age', odataName: 'the_age', forms: [ { name: 'simpleEntity', xmlFormId: 'simpleEntity' }, ] },
{ name: 'address', odataName: 'address', forms: [ { name: 'simpleEntity2', xmlFormId: 'simpleEntity2' }, ] }
{ name: 'first_name', odataName: 'first_name', forms: [{ name: 'simpleEntity', xmlFormId: 'simpleEntity' }] },
{ name: 'age', odataName: 'age', forms: [{ name: 'simpleEntity', xmlFormId: 'simpleEntity' },] }
]);

});
Expand Down Expand Up @@ -903,7 +952,7 @@ describe('datasets and entities', () => {
await asAlice.get('/v1/projects/1/datasets/people')
.expect(200)
.then(({ body }) => {
body.sourceForms.should.be.eql([ { name: 'simpleEntity', xmlFormId: 'simpleEntity' } ]);
body.sourceForms.should.be.eql([{ name: 'simpleEntity', xmlFormId: 'simpleEntity' }]);
});

}));
Expand Down Expand Up @@ -1392,7 +1441,7 @@ describe('datasets and entities', () => {
.expect(200)
.then(({ text }) => {
text.should.equal('name,label,first_name,the.age\n' +
'12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88\n');
'12345678-1234-4123-8234-123456789abc,Alice (88),Alice,88\n');
});

}));
Expand Down Expand Up @@ -2311,7 +2360,7 @@ describe('datasets and entities', () => {

await Audits.getLatestByAction('dataset.update')
.then(o => o.get())
.then(audit => audit.details.should.eql({ properties: ['first_name', 'age', 'color_name', ] }));
.then(audit => audit.details.should.eql({ properties: ['first_name', 'age', 'color_name',] }));

}));

Expand Down Expand Up @@ -2346,7 +2395,7 @@ describe('datasets and entities', () => {
container.oneFirst(sql`select count(*) from form_fields as fs join forms as f on fs."formId" = f.id where f."xmlFormId"='simpleEntity'`),
container.oneFirst(sql`select count(*) from ds_property_fields`),
])
.then((counts) => counts.should.eql([ 2, 6, 6 ]));
.then((counts) => counts.should.eql([2, 6, 6]));

}));
});
Expand Down

0 comments on commit 7b59340

Please sign in to comment.