Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
fix: update snap object keys to be mandatory and move name to metadata (
Browse files Browse the repository at this point in the history
#87)

* fix: update snap object keys to be mandatory and move name to metadata

* add snap metadata test
  • Loading branch information
montelaidev authored Aug 31, 2023
1 parent d2a02b1 commit d2b0137
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
60 changes: 59 additions & 1 deletion src/internal/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('InternalAccount', () => {
keyring: {
type: 'Test Keyring',
},
name: 'Account 1',
},
};

Expand All @@ -29,6 +30,7 @@ describe('InternalAccount', () => {
type: 'eip155:eoa',
metadata: {
keyring: {},
name: 'Account 1',
},
};

Expand All @@ -44,7 +46,9 @@ describe('InternalAccount', () => {
options: {},
methods: [],
type: 'eip155:eoa',
metadata: {},
metadata: {
name: 'Account 1',
},
};

expect(() => assert(account, InternalAccountStruct)).toThrow(
Expand Down Expand Up @@ -77,6 +81,7 @@ describe('InternalAccount', () => {
keyring: {
type: 'Test Keyring',
},
name: 'Account 1',
extra: 'field',
},
};
Expand All @@ -85,4 +90,57 @@ describe('InternalAccount', () => {
'At path: metadata.extra -- Expected a value of type `never`',
);
});

it('should contain snap name, id and enabled if the snap metadata exists', () => {
const account = {
id: '606a7759-b0fb-48e4-9874-bab62ff8e7eb',
address: '0x000',
options: {},
methods: [],
type: 'eip155:eoa',
metadata: {
keyring: {
type: 'Test Keyring',
},
name: 'Account 1',
snap: {
id: 'test-snap',
enabled: true,
name: 'Test Snap',
},
},
};

expect(() => assert(account, InternalAccountStruct)).not.toThrow();
});

it.each([['name', 'enabled', 'id']])(
'should throw if snap.%i is not set',
(key: string) => {
const account = {
id: '606a7759-b0fb-48e4-9874-bab62ff8e7eb',
address: '0x000',
options: {},
methods: [],
type: 'eip155:eoa',
metadata: {
keyring: {
type: 'Test Keyring',
},
name: 'Account 1',
snap: {
id: 'test-snap',
enabled: true,
name: 'Test Snap',
},
},
};

delete account.metadata.snap[key as keyof typeof account.metadata.snap];

const regex = new RegExp(`At path: metadata.snap.${key}`, 'u');

expect(() => assert(account, InternalAccountStruct)).toThrow(regex);
},
);
});
7 changes: 4 additions & 3 deletions src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export const InternalAccountStruct = object({
metadata: object({
snap: optional(
object({
id: optional(string()),
name: optional(string()),
enabled: optional(boolean()),
id: string(),
enabled: boolean(),
name: string(),
}),
),
name: string(),
keyring: object({
type: string(),
}),
Expand Down

0 comments on commit d2b0137

Please sign in to comment.