Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version and conflict to entity metadata odata spec #1065

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/formats/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ const edmxTemplaterForEntities = template(`<?xml version="1.0" encoding="UTF-8"?
<Property Name="creatorName" Type="Edm.String"/>
<Property Name="updates" Type="Edm.Int64"/>
<Property Name="updatedAt" Type="Edm.DateTimeOffset"/>
<Property Name="version" Type="Edm.Int64"/>
<Property Name="conflict" Type="Edm.String"/>
</ComplexType>
</Schema>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="{{fqdnBase}}">
Expand Down
42 changes: 42 additions & 0 deletions test/integration/api/odata-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,46 @@ describe('api: /datasets/:name.svc', () => {
});
}));

it('should return entity data that matches spec', testService(async (service, container) => {
const asAlice = await service.login('alice');

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

await createSubmissions(asAlice, container, 1);

await createConflict(asAlice, container);

await asAlice.get('/v1/projects/1/datasets/people.svc/Entities')
.expect(200)
.then(({ body }) => {
const entity = body.value[0];

// properties
entity.first_name.should.equal('Alicia');
entity.age.should.equal('85');

// label
entity.label.should.equal('Alicia (85)');

// id
entity.__id.should.equal('12345678-1234-4123-8234-123456789abc');

// metadata/__system data
// if any of these change, they should also be updated in the emdx template
entity.should.have.property('__system');
entity.__system.creatorId.should.equal('5');
entity.__system.creatorName.should.equal('Alice');
entity.__system.createdAt.should.be.a.recentIsoDate();
entity.__system.updatedAt.should.be.a.recentIsoDate();
entity.__system.updates.should.equal(2);
entity.__system.version.should.equal(3);
entity.__system.conflict.should.equal('hard');
});
}));

it('should return count of entities', testService(async (service, container) => {
const asAlice = await service.login('alice');

Expand Down Expand Up @@ -465,6 +505,8 @@ describe('api: /datasets/:name.svc', () => {
<Property Name="creatorName" Type="Edm.String"/>
<Property Name="updates" Type="Edm.Int64"/>
<Property Name="updatedAt" Type="Edm.DateTimeOffset"/>
<Property Name="version" Type="Edm.Int64"/>
<Property Name="conflict" Type="Edm.String"/>
</ComplexType>
</Schema>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="org.opendatakit.user.people">
Expand Down