Skip to content

Commit

Permalink
Merge pull request #68 from logion-network/feature/submitter-api
Browse files Browse the repository at this point in the history
feat: API update for file/metadata submitter .
  • Loading branch information
benoitdevos authored Jan 10, 2022
2 parents 149f1c8 + c96d2bb commit 98b7a3e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
24 changes: 24 additions & 0 deletions resources/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@
"type": "string",
"format": "date-time",
"description": "The date-time of addition (chain time)"
},
"submitter": {
"type": "string",
"description": "The SS58 address of the file submitter"
}
}
}
Expand Down Expand Up @@ -644,6 +648,10 @@
"type": "string",
"format": "date-time",
"description": "The date-time of addition (chain time)"
},
"submitter": {
"type": "string",
"description": "The SS58 address of the metadata item submitter"
}
}
}
Expand Down Expand Up @@ -716,6 +724,10 @@
"type": "string",
"format": "date-time",
"description": "The date-time of addition (chain time)"
},
"submitter": {
"type": "string",
"description": "The SS58 address of the file submitter"
}
}
}
Expand Down Expand Up @@ -764,6 +776,10 @@
"type": "string",
"format": "date-time",
"description": "The date-time of addition (chain time)"
},
"submitter": {
"type": "string",
"description": "The SS58 address of the metadata item submitter"
}
}
}
Expand Down Expand Up @@ -848,6 +864,10 @@
"nature": {
"type": "string",
"description": "The file's nature"
},
"submitter": {
"type": "string",
"description": "The SS58 address of the file submitter"
}
}
},
Expand Down Expand Up @@ -885,6 +905,10 @@
"value": {
"type": "string",
"description": "The item's value"
},
"submitter": {
"type": "string",
"description": "The SS58 address of the metadata item submitter"
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/logion/controllers/locrequest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ export class LocRequestController extends ApiController {
hash: file.hash,
nature: file.nature,
addedOn: file.addedOn?.toISOString() || undefined,
submitter: locDescription.ownerAddress // TODO Change me
})),
metadata: request.getMetadataItems().map(item => ({
name: item.name,
value: item.value,
addedOn: item.addedOn?.toISOString() || undefined,
submitter: locDescription.ownerAddress // TODO Change me
})),
links: request.getLinks().map(link => ({
target: link.target,
Expand Down Expand Up @@ -313,11 +315,13 @@ export class LocRequestController extends ApiController {
hash: file.hash,
nature: file.nature,
addedOn: file.addedOn?.toISOString() || undefined,
submitter: locDescription.ownerAddress // TODO Change me
})),
metadata: request.getMetadataItems(false).map(item => ({
name: item.name,
value: item.value,
addedOn: item.addedOn?.toISOString() || undefined
addedOn: item.addedOn?.toISOString() || undefined,
submitter: locDescription.ownerAddress // TODO Change me
})),
links: request.getLinks(false).map(link => ({
target: link.target,
Expand Down
8 changes: 6 additions & 2 deletions test/unit/controllers/locrequest.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const testUserIdentity = {
}

const IDENTITY_LOC_ID = "6b00b9f2-4439-4c4a-843e-2ea3ce2016fd";
const SUBMITTER = "5DDGQertEH5qvKVXUmpT3KNGViCX582Qa2WWb8nGbkmkRHvw";

const identityInIdentityLoc = {
firstName: "Felix",
Expand Down Expand Up @@ -306,7 +307,7 @@ describe('LocRequestController', () => {
const buffer = Buffer.from(SOME_DATA);
await request(app)
.post(`/api/loc-request/${ REQUEST_ID }/files`)
.field({ nature: "some nature" })
.field({ nature: "some nature", submitter: SUBMITTER })
.attach('file', buffer, {
filename: FILE_NAME,
contentType: 'text/plain',
Expand Down Expand Up @@ -351,6 +352,7 @@ describe('LocRequestController', () => {
expect(file.nature).toBe(testFile.nature)
expect(file.hash).toBe(testFile.hash)
expect(file.addedOn).toBe(testFile.addedOn?.toISOString())
expect(file.submitter).toBe(ALICE) // TODO Change me
const link = response.body.links[0]
expect(link.nature).toBe(testLink.nature)
expect(link.target).toBe(testLink.target)
Expand All @@ -359,6 +361,7 @@ describe('LocRequestController', () => {
expect(metadataItem.name).toBe(testMetadataItem.name)
expect(metadataItem.value).toBe(testMetadataItem.value)
expect(metadataItem.addedOn).toBe(testMetadataItem.addedOn?.toISOString())
expect(metadataItem.submitter).toBe(ALICE) // TODO Change me
});
});

Expand All @@ -381,7 +384,7 @@ describe('LocRequestController', () => {
const app = setupApp(LocRequestController, (container) => mockModelForAllItems(container, locRequest))
await request(app)
.post(`/api/loc-request/${ REQUEST_ID }/metadata`)
.send({ name: SOME_DATA_NAME, value: SOME_DATA_VALUE })
.send({ name: SOME_DATA_NAME, value: SOME_DATA_VALUE, submitter: SUBMITTER })
.expect(204)
locRequest.verify(instance => instance.addMetadataItem(
It.Is<MetadataItemDescription>(item => item.name == SOME_DATA_NAME && item.value == SOME_DATA_VALUE)))
Expand Down Expand Up @@ -682,6 +685,7 @@ const SOME_FILE = {
hash: SOME_DATA_HASH,
oid: SOME_OID,
nature: "file-nature",
submitter: SUBMITTER
};

async function fileExists(filePath: string): Promise<boolean> {
Expand Down

0 comments on commit 98b7a3e

Please sign in to comment.