Skip to content

Commit

Permalink
feat: support for about in claims (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarodragan authored Aug 11, 2019
1 parent b00595e commit 939e83d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
11 changes: 9 additions & 2 deletions src/modules/Works/Works.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const legacyContext = {
content: 'schema:text',
}

const aboutContext = {
about: {
'@id': 'schema:url',
'@container': '@list',
},
}

export interface WorkAttributes {
readonly [key: string]: string
}
Expand All @@ -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) {
Expand Down
36 changes: 18 additions & 18 deletions test/Integration/works/getWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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')
})
})
Expand Down Expand Up @@ -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')
})
})

Expand All @@ -194,7 +194,7 @@ describe('Works', async function() {
'author',
'tags',
'hash',
'archiveUrl',
'about',
'extra',
)
expect(work.extra).to.be.eq(extra)
Expand Down
12 changes: 6 additions & 6 deletions test/Integration/works/getWorks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -60,7 +60,7 @@ describe('Works', async function() {
'author',
'tags',
'hash',
'archiveUrl',
'about',
)
expect(works[1]).to.have.all.keys(
'name',
Expand All @@ -69,7 +69,7 @@ describe('Works', async function() {
'author',
'tags',
'hash',
'archiveUrl',
'about',
)
})
})
Expand All @@ -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)
Expand All @@ -112,7 +112,7 @@ describe('Works', async function() {
'author',
'tags',
'hash',
'archiveUrl',
'about',
)
expect(works[1]).to.have.all.keys(
'name',
Expand All @@ -121,7 +121,7 @@ describe('Works', async function() {
'author',
'tags',
'hash',
'archiveUrl',
'about',
)
})
})
Expand Down

0 comments on commit 939e83d

Please sign in to comment.