From 1ceea37fb5e42ae74443683e200e230a5f04e0ac Mon Sep 17 00:00:00 2001 From: Frank Hinek Date: Tue, 16 May 2023 20:46:56 -0400 Subject: [PATCH] Update test profiles to use DWN node variable and pointed back to hosted nodes again Signed-off-by: Frank Hinek --- packages/web5/tests/fixtures/test-profiles.ts | 14 +++++++----- packages/web5/tests/web5-dwn.spec.ts | 22 +++++++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/web5/tests/fixtures/test-profiles.ts b/packages/web5/tests/fixtures/test-profiles.ts index fa5a820e9..ead8e8eb3 100644 --- a/packages/web5/tests/fixtures/test-profiles.ts +++ b/packages/web5/tests/fixtures/test-profiles.ts @@ -3,6 +3,9 @@ import type { TestProfileOptions } from '../test-utils/test-user-agent.js'; import { generateKeyPair } from '@decentralized-identity/ion-tools'; +const dwnNodes = ['https://dwn.tbddev.org/dwn0']; +// const dwnNodes = ['http://localhost:3000']; + export const keyIds = { did: { service: { @@ -54,12 +57,13 @@ export const ionCreateOptions = { authorization: { encryption: { attestation: { + + // Authorization, Encryption, and Attestation keys. keys: async (): Promise => { let profileKeys: KeyOption[] = []; profileKeys.push(await keys.secp256k1.jwk.attestation()); profileKeys.push(await keys.secp256k1.jwk.authorization()); profileKeys.push(await keys.secp256k1.jwk.encryption()); - return { keys : profileKeys, services : [ @@ -67,8 +71,7 @@ export const ionCreateOptions = { id : 'dwn', type : 'DecentralizedWebNode', serviceEndpoint : { - nodes : ['http://localhost:3000'], - // nodes : ['https://dwn.tbddev.org/dwn0'], + nodes : dwnNodes, messageAttestationKeys : [`#${keyIds.did.service.dwn.attestation}`], messageAuthorizationKeys : [`#${keyIds.did.service.dwn.authorization}`], recordEncryptionKeys : [`#${keyIds.did.service.dwn.encryption}`] @@ -80,18 +83,17 @@ export const ionCreateOptions = { } }, + // Authorization and Encryption keys. keys: async (): Promise => { let profileKeys: KeyOption[] = []; profileKeys.push(await keys.secp256k1.jwk.authorization()); - return { keys : profileKeys, services : [{ id : 'dwn', type : 'DecentralizedWebNode', serviceEndpoint : { - nodes : ['http://localhost:3000'], - // nodes : ['https://dwn.tbddev.org/dwn0'], + nodes : dwnNodes, messageAuthorizationKeys : [`#${keyIds.did.service.dwn.authorization}`], } }] diff --git a/packages/web5/tests/web5-dwn.spec.ts b/packages/web5/tests/web5-dwn.spec.ts index 54fd36597..8af3eb59f 100644 --- a/packages/web5/tests/web5-dwn.spec.ts +++ b/packages/web5/tests/web5-dwn.spec.ts @@ -107,9 +107,10 @@ describe('web5.dwn', () => { describe('records', () => { describe('write', () => { describe('agent', () => { - it('writes a record', async () => { + it('writes a record with string data', async () => { + const dataString = 'Hello, world!'; const result = await dwn.records.write({ - data : 'Hello, world!', + data : dataString, message : { schema : 'foo/bar', dataFormat : 'text/plain' @@ -119,6 +120,23 @@ describe('web5.dwn', () => { expect(result.status.code).to.equal(202); expect(result.status.detail).to.equal('Accepted'); expect(result.record).to.exist; + expect(await result.record?.data.text()).to.equal(dataString); + }); + + it('writes a record with JSON data', async () => { + const dataJson = { hello: 'world!'}; + const result = await dwn.records.write({ + data : dataJson, + message : { + schema : 'foo/bar', + dataFormat : 'application/json' + } + }); + + expect(result.status.code).to.equal(202); + expect(result.status.detail).to.equal('Accepted'); + expect(result.record).to.exist; + expect(await result.record?.data.json()).to.deep.equal(dataJson); }); });