-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,69 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { sign } from '@stablelib/ed25519'; | ||
import { toString, fromString } from 'uint8arrays'; | ||
import { toString } from 'uint8arrays'; | ||
import { getDidDocument, privKeyBytes, setResourceId } from 'fixtures'; | ||
|
||
let didUrlState; | ||
let resourceJobId; | ||
test.describe('Resource creat workflow', () => { | ||
let didUrlState; | ||
let resourceJobId; | ||
|
||
test('resource-create. Initiate Resource creation procedure', async ({ request }) => { | ||
const didPayload = getDidDocument(); | ||
const payload = await request.post(`/1.0/createResource`, { | ||
data: { | ||
did: didPayload.id, | ||
content: 'SGVsbG8gV29ybGQ=', | ||
name: 'ResourceName', | ||
type: 'TextDocument', | ||
version: '1.0', | ||
options: { | ||
network: 'testnet', | ||
test('resource-create. Initiate Resource creation procedure', async ({ request }) => { | ||
const didPayload = getDidDocument(); | ||
const payload = await request.post(`/1.0/createResource`, { | ||
data: { | ||
did: didPayload.id, | ||
content: 'SGVsbG8gV29ybGQ=', | ||
name: 'ResourceName', | ||
type: 'TextDocument', | ||
version: '1.0', | ||
options: { | ||
network: 'testnet', | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
expect(payload.status()).toBe(200); | ||
expect(payload.status()).toBe(200); | ||
|
||
const body = await payload.json(); | ||
expect(body.didUrlState).toBeDefined(); | ||
expect(body.didUrlState.didUrl).toBeDefined(); | ||
expect(body.didUrlState.state).toBeDefined(); | ||
expect(body.didUrlState.signingRequest).toBeDefined(); | ||
const body = await payload.json(); | ||
expect(body.didUrlState).toBeDefined(); | ||
expect(body.didUrlState.didUrl).toBeDefined(); | ||
expect(body.didUrlState.state).toBeDefined(); | ||
expect(body.didUrlState.signingRequest).toBeDefined(); | ||
|
||
didUrlState = body.didUrlState; | ||
resourceJobId = body.jobId; | ||
}); | ||
didUrlState = body.didUrlState; | ||
resourceJobId = body.jobId; | ||
}); | ||
|
||
test('resource-create. Send the final request for Resource creation', async ({ request }) => { | ||
const didPayload = getDidDocument(); | ||
const serializedPayload = didUrlState.signingRequest[0].serializedPayload; | ||
const serializedBytes = Buffer.from(serializedPayload, 'base64'); | ||
const signature = sign(privKeyBytes, serializedBytes); | ||
test('resource-create. Send the final request for Resource creation', async ({ request }) => { | ||
const serializedPayload = didUrlState.signingRequest[0].serializedPayload; | ||
Check failure on line 38 in tests/resource/02-createResource.spec.ts GitHub Actions / Build & Test / Build Node.js[Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation
Check failure on line 38 in tests/resource/02-createResource.spec.ts GitHub Actions / Build & Test / Build Node.js[Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation
|
||
const serializedBytes = Buffer.from(serializedPayload, 'base64'); | ||
const signature = sign(privKeyBytes, serializedBytes); | ||
|
||
const secret = { | ||
signingResponse: [ | ||
{ | ||
kid: didUrlState.signingRequest[0].kid, | ||
signature: toString(signature, 'base64'), | ||
}, | ||
], | ||
}; | ||
const secret = { | ||
signingResponse: [ | ||
{ | ||
kid: didUrlState.signingRequest[0].kid, | ||
signature: toString(signature, 'base64'), | ||
}, | ||
], | ||
}; | ||
|
||
const resourceCreate = await request.post(`/1.0/createResource`, { | ||
data: { | ||
did: didPayload.id, | ||
content: 'SGVsbG8gV29ybGQ=', | ||
name: 'ResourceName', | ||
type: 'TextDocument', | ||
version: '1.0', | ||
jobId: resourceJobId, | ||
secret: secret, | ||
options: { | ||
network: 'testnet', | ||
const resourceCreate = await request.post(`/1.0/createResource`, { | ||
data: { | ||
jobId: resourceJobId, | ||
secret: secret, | ||
}, | ||
}, | ||
}); | ||
const response = await resourceCreate.json(); | ||
expect(resourceCreate.status()).toBe(201); | ||
Check failure on line 58 in tests/resource/02-createResource.spec.ts GitHub Actions / Build & Test / Build Node.js[Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation
|
||
expect(response.didUrlState).toBeDefined(); | ||
expect(response.didUrlState.didUrl).toBeDefined(); | ||
expect(response.didUrlState.state).toBeDefined(); | ||
expect(response.didUrlState.state).toEqual('finished'); | ||
expect(response.didUrlState.name).toEqual('ResourceName'); | ||
expect(response.didUrlState.type).toEqual('TextDocument'); | ||
expect(response.didUrlState.version).toEqual('1.0'); | ||
console.log('DIDUrl:' + response.didUrlState.didUrl); | ||
setResourceId(response.didUrlState.didUrl.split('/resources/')[1]); | ||
}); | ||
const response = await resourceCreate.json(); | ||
expect(resourceCreate.status()).toBe(201); | ||
expect(response.didUrlState).toBeDefined(); | ||
expect(response.didUrlState.didUrl).toBeDefined(); | ||
expect(response.didUrlState.state).toBeDefined(); | ||
expect(response.didUrlState.state).toEqual('finished'); | ||
expect(response.didUrlState.name).toEqual('ResourceName'); | ||
expect(response.didUrlState.type).toEqual('TextDocument'); | ||
expect(response.didUrlState.version).toEqual('1.0'); | ||
console.log('DIDUrl:' + response.didUrlState.didUrl); | ||
setResourceId(response.didUrlState.didUrl.split('/resources/')[1]); | ||
}); |