Skip to content

Commit

Permalink
Update test profiles to use DWN node variable and pointed back to hos…
Browse files Browse the repository at this point in the history
…ted nodes again

Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek committed May 17, 2023
1 parent ad86127 commit 1ceea37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 8 additions & 6 deletions packages/web5/tests/fixtures/test-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -54,21 +57,21 @@ export const ionCreateOptions = {
authorization: {
encryption: {
attestation: {

// Authorization, Encryption, and Attestation keys.
keys: async (): Promise<DidIonCreateOptions> => {
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 : [
{
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}`]
Expand All @@ -80,18 +83,17 @@ export const ionCreateOptions = {
}
},

// Authorization and Encryption keys.
keys: async (): Promise<DidIonCreateOptions> => {
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}`],
}
}]
Expand Down
22 changes: 20 additions & 2 deletions packages/web5/tests/web5-dwn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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);
});
});

Expand Down

0 comments on commit 1ceea37

Please sign in to comment.