Skip to content

Commit

Permalink
test: Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Oct 5, 2020
1 parent 6446f2d commit 297c8d4
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 3 deletions.
2 changes: 2 additions & 0 deletions __tests__/graphqlAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import webDidFlow from './shared/webDidFlow'
import documentationExamples from './shared/documentationExamples'
import keyManager from './shared/keyManager'
import identityManager from './shared/identityManager'
import messageHandler from './shared/messageHandler'

const databaseFile = 'graphql-database.sqlite'
const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'
Expand Down Expand Up @@ -171,4 +172,5 @@ describe('GraphQL integration tests', () => {
documentationExamples(testContext)
keyManager(testContext)
identityManager(testContext)
messageHandler(testContext)
})
2 changes: 2 additions & 0 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import saveClaims from './shared/saveClaims'
import documentationExamples from './shared/documentationExamples'
import keyManager from './shared/keyManager'
import identityManager from './shared/identityManager'
import messageHandler from './shared/messageHandler'

const databaseFile = 'local-database.sqlite'
const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'
Expand Down Expand Up @@ -151,4 +152,5 @@ describe('Local integration tests', () => {
documentationExamples(testContext)
keyManager(testContext)
identityManager(testContext)
messageHandler(testContext)
})
3 changes: 3 additions & 0 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import webDidFlow from './shared/webDidFlow'
import documentationExamples from './shared/documentationExamples'
import keyManager from './shared/keyManager'
import identityManager from './shared/identityManager'
import messageHandler from './shared/messageHandler'


const databaseFile = 'rest-database.sqlite'
const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'
Expand Down Expand Up @@ -164,4 +166,5 @@ describe('REST integration tests', () => {
documentationExamples(testContext)
keyManager(testContext)
identityManager(testContext)
messageHandler(testContext)
})
32 changes: 29 additions & 3 deletions __tests__/shared/handleSdrMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TAgent, IIdentityManager, IIdentity, IDataStore, IMessageHandler } from '../../packages/daf-core/src'
import { ICredentialIssuer } from '../../packages/daf-w3c/src'
import { ISelectiveDisclosure } from '../../packages/daf-selective-disclosure/src'
import { ISelectiveDisclosure, SelectiveDisclosure } from '../../packages/daf-selective-disclosure/src'
import { IDataStoreORM } from '../../packages/daf-typeorm/src'

type ConfiguredAgent = TAgent<
Expand All @@ -15,9 +15,9 @@ export default (testContext: {
describe('handling sdr message', () => {
let agent: ConfiguredAgent
let identity: IIdentity
const JWT =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1OTM0NTE3MDAsInR5cGUiOiJzZHIiLCJzdWJqZWN0IjoiZGlkOmV0aHI6cmlua2VieToweDM2MjQ2M2NiZTUyMjhjZTUwMGJlOGUwMzVjZGIyMWI3NzQ1ZjZkYjAiLCJ0YWciOiJzZHItb25lIiwiY2xhaW1zIjpbeyJyZWFzb24iOiJXZSBuZWVkIGl0IiwiY2xhaW1UeXBlIjoibmFtZSIsImVzc2VudGlhbCI6dHJ1ZX1dLCJpc3MiOiJkaWQ6ZXRocjpyaW5rZWJ5OjB4MTM4NGMxZmNlM2Y3MWQ3NjU5NzcwOGY1NGM0ZDEyOGMyNDFkMDBkMiJ9.L-j-gREAuN7DAxDCe1vXJWtMIdmn88HTuTFp2PasTTo_aqvIdGcFtv-rSfvRHkauNq5C3PkXkQWY01VGqpJ-QwE'
let JWT: string
let originalRequestSender: string
let sdr: SelectiveDisclosure

beforeAll(() => {
testContext.setup()
Expand Down Expand Up @@ -49,6 +49,18 @@ export default (testContext: {
})

it('should save an SDR message', async () => {
JWT = await agent.createSelectiveDisclosureRequest({
data: {
issuer: identity.did,
tag: 'sdr-one',
claims: [{
reason: 'We need it',
claimType: 'name',
essential: true
}]
}
})

const message = await agent.handleMessage({
raw: JWT,
save: true,
Expand Down Expand Up @@ -131,6 +143,20 @@ export default (testContext: {
})

expect(verifiablePresentation).toHaveProperty('proof.jwt')


const validated = await agent.validatePresentationAgainstSdr({
presentation: verifiablePresentation,
sdr: {
issuer: '',
claims: [
{
claimType: 'name',
},
],
},
})
expect(validated.valid).toEqual(true)
})
})
}
59 changes: 59 additions & 0 deletions __tests__/shared/messageHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { TAgent, IDataStore, IMessageHandler, IMessage } from '../../packages/daf-core/src'
import { IDataStoreORM } from '../../packages/daf-typeorm/src'

type ConfiguredAgent = TAgent<IDataStore & IMessageHandler & IDataStoreORM>

export default (testContext: {
getAgent: () => ConfiguredAgent
setup: () => Promise<boolean>
tearDown: () => Promise<boolean>
}) => {
describe('message handler', () => {
let agent: ConfiguredAgent

beforeAll(async () => {
await testContext.setup()
agent = testContext.getAgent()
return true
})
afterAll(testContext.tearDown)

let parsedMessage: IMessage

it('should parse raw message', async () => {
const raw = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODg2NzY3MzksInZwIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZVByZXNlbnRhdGlvbiJdLCJ2ZXJpZmlhYmxlQ3JlZGVudGlhbCI6WyJleUowZVhBaU9pSktWMVFpTENKaGJHY2lPaUpGVXpJMU5rc3RVaUo5LmV5SnBZWFFpT2pFMU9ESTJNVGsyTnpZc0luTjFZaUk2SW1ScFpEcGxkR2h5T25KcGJtdGxZbms2TUhnell6TTFOMkpoTkRVNE9UTXpZVEU1WXpGa1pqRmpOMlkyWWpRM00ySXpNekF5WW1KaVpUWXhJaXdpZG1NaU9uc2lRR052Ym5SbGVIUWlPbHNpYUhSMGNITTZMeTkzZDNjdWR6TXViM0puTHpJd01UZ3ZZM0psWkdWdWRHbGhiSE12ZGpFaVhTd2lkSGx3WlNJNld5SldaWEpwWm1saFlteGxRM0psWkdWdWRHbGhiQ0pkTENKamNtVmtaVzUwYVdGc1UzVmlhbVZqZENJNmV5SnVZVzFsSWpvaVFXeHBZMlVpZlgwc0ltbHpjeUk2SW1ScFpEcGxkR2h5T25KcGJtdGxZbms2TUhnell6TTFOMkpoTkRVNE9UTXpZVEU1WXpGa1pqRmpOMlkyWWpRM00ySXpNekF5WW1KaVpUWXhJbjAuSUdGMUxGT2M0X1BjR1ZlcTdZdzdPR3o0R2o3eFhaSzZwOGJQOUNTRUlYejdtTkZQTTB2MG51ZXZUWjQ3YTBJOFhnTGZDRk5rVXJJSXNjakg4TUZ4X3dFIl19LCJ0YWciOiJ0YWcxMjMiLCJhdWQiOlsiZGlkOmV4YW1wbGU6MzQ1NiIsImRpZDp3ZWI6dXBvcnQubWUiXSwiaXNzIjoiZGlkOmV0aHI6cmlua2VieToweGIwOWI2NjAyNmJhNTkwOWE3Y2ZlOTliNzY4NzU0MzFkMmI4ZDUxOTAifQ.4SWpp8siCBHP47KrOT_28IJIQPZLCWO9VS0Ir-VVYOGUAVj7vHtXLxl3Y6lLAxYeNqWrRPCAVkDArBFCNRjYUgA'
parsedMessage = await agent.handleMessage({
raw,
save: false,
metaData: [{type: 'test'}],
})
expect(typeof parsedMessage.id).toEqual('string')

})

it('should save message', async () => {
const id = await agent.dataStoreSaveMessage({ message: parsedMessage })
expect(id).toEqual(parsedMessage.id)
})

it('should get message from db', async () => {
const message = await agent.dataStoreGetMessage({ id: parsedMessage.id })
expect(message).toEqual({...parsedMessage, ...{replyTo: null, replyUrl: null}})
})

it('should throw error for non existing message', async () => {
await expect(
agent.dataStoreGetMessage({
id: 'foobar',
}),
).rejects.toThrow('Message not found')
})

it('should count messages', async () => {
const allMessages = await agent.dataStoreORMGetMessages()
const count = await agent.dataStoreORMGetMessagesCount()
expect(allMessages.length).toEqual(count)
})

})
}
4 changes: 4 additions & 0 deletions __tests__/shared/saveClaims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export default (testContext: {
where: [{ column: 'type', value: ['topic'] }],
})
expect(credentials).toHaveLength(3)
const count = await agent.dataStoreORMGetVerifiableCredentialsByClaimsCount({
where: [{ column: 'type', value: ['topic'] }],
})
expect(count).toEqual(credentials.length)
})

it('should be able to find all the credentials when query by claim type and value', async () => {
Expand Down

0 comments on commit 297c8d4

Please sign in to comment.