Skip to content

Commit

Permalink
Removed some boilerplate code about PUT and RESTORE for entities (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite authored May 16, 2023
1 parent 5e5e8c6 commit 43a150b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 159 deletions.
100 changes: 0 additions & 100 deletions lib/resources/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@ const { Entity } = require('../model/frames');
const Problem = require('../util/problem');
const { diffEntityData } = require('../data/entity');

const getEntityDef = () => ({
versionNumber: 1,
label: '',
current: true,
createdAt: '2023-01-01T09:00:00.000Z',
creatorId: 1,
userAgent: 'Postman'
});

const getEntity = (i) => ({
uuid: `00000000-0000-0000-0000-00000000000${i}`,
createdAt: '2023-01-01T09:00:00.000Z',
updatedAt: null,
deletedAt: null,
creatorId: 1
});

module.exports = (service, endpoint) => {

service.get('/projects/:projectId/datasets/:name/entities', endpoint(async ({ Datasets, Entities }, { params, auth, queryOptions }) => {
Expand Down Expand Up @@ -64,30 +47,6 @@ module.exports = (service, endpoint) => {
return defs;
}));

// May not be needed for now
service.get('/projects/:id/datasets/:name/entities/:uuid/versions/:versionNumber', endpoint(async ({ Projects }, { params, queryOptions }) => {

await Projects.getById(params.id, queryOptions).then(getOrNotFound);

return {
...getEntityDef(),
current: false,
source: {
type: 'api',
details: null
},
data: {
firstName: 'Janie',
lastName: 'Doe',
city: 'Toronto'
},
versionNumber: params.versionNumber,
label: 'Janie Doe',
createdAt: new Date()
};

}));

service.get('/projects/:projectId/datasets/:name/entities/:uuid/diffs', endpoint(async ({ Datasets, Entities }, { params, auth, queryOptions }) => {

const dataset = await Datasets.get(params.projectId, params.name, true).then(getOrNotFound);
Expand Down Expand Up @@ -131,39 +90,6 @@ module.exports = (service, endpoint) => {
return Entities.getById(dataset.id, entity.uuid).then(getOrNotFound);
}));

service.put('/projects/:id/datasets/:name/entities/:uuid', endpoint(async ({ Projects }, { params, queryOptions, body, headers }) => {

await Projects.getById(params.id, queryOptions).then(getOrNotFound);

const { uuid, label, ...data } = body;

const updatedAt = new Date();

const userAgent = headers['user-agent'];

const entity = {
...getEntity(1),
uuid,
createdAt: '2023-01-01T09:00:00.000Z',
updatedAt,
currentVersion: {
...getEntityDef(),
userAgent,
versionNumber: 2,
source: {
type: 'api',
details: null
},
label,
createdAt: updatedAt,
data
}
};

return entity;

}));

service.patch('/projects/:id/datasets/:name/entities/:uuid', endpoint(async ({ Datasets, Entities }, { auth, body, headers, params, query }) => {

const dataset = await Datasets.get(params.id, params.name).then(getOrNotFound);
Expand Down Expand Up @@ -193,30 +119,4 @@ module.exports = (service, endpoint) => {
return success();

}));

// Lowest priority
service.post('/projects/:id/datasets/:name/entities/:uuid/restore', endpoint(async ({ Projects }, { params, queryOptions }) => {

await Projects.getById(params.id, queryOptions).then(getOrNotFound);

const entity = getEntity(1);
entity.updatedAt = '2023-01-02T09:00:00.000Z';
entity.currentVersion = {
...getEntityDef(),
source: {
type: 'api',
details: null
},
data: {
firstName: 'Jane',
lastName: 'Roe',
city: 'Toronto'
},
versionNumber: 1,
label: 'Jane Roe',
createdAt: '2023-01-03T09:00:00.000Z'
};
return entity;

}));
};
59 changes: 0 additions & 59 deletions test/integration/api/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,39 +697,6 @@ describe('Entities API', () => {
}));
});

describe('PUT /datasets/:name/entities/:uuid', () => {

it('should update an Entity', testService(async (service) => {
const asAlice = await service.login('alice');

await asAlice.put('/v1/projects/1/datasets/People/entities/10000000-0000-0000-0000-000000000001')
.send({
uuid: '10000000-0000-0000-0000-000000000001',
label: 'Richard Roe',
firstName: 'Richard',
lastName: 'Roe',
city: 'Toronto'
})
.expect(200)
.then(({ body: person }) => {
person.should.be.an.Entity();
person.should.have.property('currentVersion').which.is.an.EntityDef();
person.currentVersion.should.have.property('source').which.is.an.EntitySource();
person.currentVersion.should.have.property('data').which.is.eql({
firstName: 'Richard',
lastName: 'Roe',
city: 'Toronto'
});
});
}));

// it should reject if uuid is not found
// it should reject if uuid in queryParam and body don't match
// it should reject if uuid or label is missing
// it should reject if property is not present in dataset.publishedProperties
// it should reject if user don't have permission
});

describe('PATCH /datasets/:name/entities/:uuid', () => {
it('should return notfound if the dataset does not exist', testEntities(async (service) => {
const asAlice = await service.login('alice');
Expand Down Expand Up @@ -1049,30 +1016,4 @@ describe('Entities API', () => {
}));

});

// Lowest Priority
describe.skip('POST /datasets/:name/entities/:uuid/restore', () => {

it('should restore a deleted Entity', testService(async (service) => {
const asAlice = await service.login('alice');

await asAlice.post('/v1/projects/1/datasets/People/entities/10000000-0000-0000-0000-000000000001/restore')
.expect(200)
.then(({ body: person }) => {
person.should.be.an.Entity();
person.should.have.property('currentVersion').which.is.an.EntityDef();
person.currentVersion.should.have.property('source').which.is.an.EntitySource();
person.currentVersion.should.have.property('data').which.is.eql({
firstName: 'Jane',
lastName: 'Roe',
city: 'Toronto'
});
});
}));

// it should reject if uuid is not found or is not deleted
// it should reject if body is not empty
// it should reject if user don't have permission

});
});

0 comments on commit 43a150b

Please sign in to comment.