From 939e83da74c131cb73f0a7555b6b498355a7fd28 Mon Sep 17 00:00:00 2001 From: Lautaro Dragan Date: Sat, 10 Aug 2019 21:31:49 -0300 Subject: [PATCH] feat: support for `about` in claims (#979) --- src/modules/Works/Works.controller.ts | 11 ++++++-- test/Integration/works/getWork.ts | 36 +++++++++++++-------------- test/Integration/works/getWorks.ts | 12 ++++----- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/modules/Works/Works.controller.ts b/src/modules/Works/Works.controller.ts index e6ea7731f..57eb4dbe5 100644 --- a/src/modules/Works/Works.controller.ts +++ b/src/modules/Works/Works.controller.ts @@ -15,6 +15,13 @@ const legacyContext = { content: 'schema:text', } +const aboutContext = { + about: { + '@id': 'schema:url', + '@container': '@list', + }, +} + export interface WorkAttributes { readonly [key: string]: string } @@ -31,12 +38,12 @@ export class WorksController { async generateClaim(issuer: string, privateKey: string, work: WorkAttributes, context: any) { const createAndSignClaim = pipeP( - configureCreateVerifiableClaim({ issuer, context: { ...legacyContext, ...context} }), + configureCreateVerifiableClaim({ issuer, context: { ...legacyContext, ...context, ...aboutContext} }), getVerifiableClaimSigner().configureSignVerifiableClaim({ privateKey }), ) const { archiveUrl, hash } = (await this.uploadContent(work.content))[0] const newWork = omit(['content'], work) - return createAndSignClaim({ archiveUrl, hash, ...newWork }) + return createAndSignClaim({ about: [ archiveUrl ], hash, ...newWork }) } async create(workAttributes: any) { diff --git a/test/Integration/works/getWork.ts b/test/Integration/works/getWork.ts index 549d86973..c8081f029 100644 --- a/test/Integration/works/getWork.ts +++ b/test/Integration/works/getWork.ts @@ -35,7 +35,7 @@ describe('Works', async function() { }) describe('When a newly created work with content has been sucessfully created', function() { - it('Should return the work with a hash and archiveUrl of the content', async function() { + it('Should return the work with a hash and about of the content', async function() { const user = await createUserVerified(mail, frost) const { token } = user const { apiToken } = await frost.createApiToken(token, Network.LIVE) @@ -48,14 +48,14 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) expect(work).to.not.have.key('content') expect(work.author).to.eql(createWork().author) }) }) describe('When a newly created work with content has been successfully created', function() { - it.skip('Should be able to download the archiveUrl', async function() { + it.skip('Should be able to download the about', async function() { const user = await createUserVerified(mail, frost) const { token } = user const { apiToken } = await frost.createApiToken(token, Network.LIVE) @@ -69,22 +69,22 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) expect(work).to.not.have.key('content') - const savedText = await fetch(work.archiveUrl).then((res: any) => res.text()) + const savedText = await fetch(work.about[0]).then((res: any) => res.text()) expect(savedText).to.eq(content) expect(work.hash).to.eq('QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm') }) }) - describe('When a newly createrd work with an archiveUrl and a hash has been successfully created', function() { - it('Should return the work with the provided hash and archiveUrl', async function() { + describe('When a newly createrd work with an about and a hash has been successfully created', function() { + it('Should return the work with the provided hash and about', async function() { const user = await createUserVerified(mail, frost) const { token } = user const { apiToken } = await frost.createApiToken(token, Network.LIVE) const work = { ...omit(['content'], createWork()), - archiveUrl: 'https://example.com/myWork', + about: [ 'https://example.com/myWork' ], hash: 'this-is-a-hash', } const { workId } = await frost.createWork(apiToken, work) @@ -96,23 +96,23 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) expect(retrievedWork).to.not.have.key('content') - expect(retrievedWork.archiveUrl).to.eq(work.archiveUrl) + expect(retrievedWork.about[0]).to.eq(work.about[0]) expect(retrievedWork.hash).to.eq(work.hash) }) }) - describe('When a newly createrd work with an archiveUrl and a hash AND content has been successfully created', - function() { - it('Should return the work with the provided hash and archiveUrl', async function() { + describe('When a work with an about and a hash AND content has been successfully created', function() { + it('Should return the work with the provided hash and about', async function() { const user = await createUserVerified(mail, frost) const { token } = user const { apiToken } = await frost.createApiToken(token, Network.LIVE) + const about = 'https://example.com/myWork' const work = { ...createWork(), - archiveUrl: 'https://example.com/myWork', + about: [ about ], hash: 'this-is-a-hash', } const { workId } = await frost.createWork(apiToken, work) @@ -124,10 +124,10 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) expect(retrievedWork).to.not.have.key('content') - expect(retrievedWork.archiveUrl).to.eq('https://example.com/myWork') + expect(retrievedWork.about[0]).to.eq(about) expect(retrievedWork.hash).to.eq('this-is-a-hash') }) }) @@ -173,7 +173,7 @@ describe('Works', async function() { const { apiToken } = await frost.createApiToken(token, Network.TEST) const { workId } = await frost.createWork(apiToken, createWork()) const work = await frost.getWork(apiToken, workId) - expect(work).to.have.all.keys('name', 'datePublished', 'dateCreated', 'author', 'tags', 'hash', 'archiveUrl') + expect(work).to.have.all.keys('name', 'datePublished', 'dateCreated', 'author', 'tags', 'hash', 'about') }) }) @@ -194,7 +194,7 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', 'extra', ) expect(work.extra).to.be.eq(extra) diff --git a/test/Integration/works/getWorks.ts b/test/Integration/works/getWorks.ts index e64709357..5a5e16171 100644 --- a/test/Integration/works/getWorks.ts +++ b/test/Integration/works/getWorks.ts @@ -44,7 +44,7 @@ describe('Works', async function() { }) describe('When there are 2 works with content', function() { - it('Should return 2 works with the hash and archiveUrl', async function() { + it('Should return 2 works with the hash and about', async function() { const user = await createUserVerified(mail, frost) const { token } = user const { apiToken } = await frost.createApiToken(token, Network.LIVE) @@ -60,7 +60,7 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) expect(works[1]).to.have.all.keys( 'name', @@ -69,7 +69,7 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) }) }) @@ -96,7 +96,7 @@ describe('Works', async function() { }) describe('When there are 2 works with content', function() { - it('Should return 2 works with hash and archiveUrl', async function() { + it('Should return 2 works with hash and about', async function() { const user = await createUserVerified(mail, frost) const { token } = user const { apiToken } = await frost.createApiToken(token, Network.TEST) @@ -112,7 +112,7 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) expect(works[1]).to.have.all.keys( 'name', @@ -121,7 +121,7 @@ describe('Works', async function() { 'author', 'tags', 'hash', - 'archiveUrl', + 'about', ) }) })