Skip to content

Commit fab0656

Browse files
committed
add metadata properties to SubscriptionController
1 parent b9cd824 commit fab0656

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

packages/subscription-controller/src/SubscriptionController.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Messenger } from '@metamask/base-controller';
1+
import { deriveStateFromMetadata, Messenger } from '@metamask/base-controller';
22

33
import {
44
controllerName,
@@ -819,4 +819,66 @@ describe('SubscriptionController', () => {
819819
});
820820
});
821821
});
822+
823+
describe('metadata', () => {
824+
it('includes expected state in debug snapshots', async () => {
825+
await withController(({ controller }) => {
826+
expect(
827+
deriveStateFromMetadata(
828+
controller.state,
829+
controller.metadata,
830+
'anonymous',
831+
),
832+
).toMatchInlineSnapshot(`Object {}`);
833+
});
834+
});
835+
836+
it('includes expected state in state logs', async () => {
837+
await withController(({ controller }) => {
838+
expect(
839+
deriveStateFromMetadata(
840+
controller.state,
841+
controller.metadata,
842+
'includeInStateLogs',
843+
),
844+
).toMatchInlineSnapshot(`
845+
Object {
846+
"subscriptions": Array [],
847+
}
848+
`);
849+
});
850+
});
851+
852+
it('persists expected state', async () => {
853+
await withController(({ controller }) => {
854+
expect(
855+
deriveStateFromMetadata(
856+
controller.state,
857+
controller.metadata,
858+
'persist',
859+
),
860+
).toMatchInlineSnapshot(`
861+
Object {
862+
"subscriptions": Array [],
863+
}
864+
`);
865+
});
866+
});
867+
868+
it('exposes expected state to UI', async () => {
869+
await withController(({ controller }) => {
870+
expect(
871+
deriveStateFromMetadata(
872+
controller.state,
873+
controller.metadata,
874+
'usedInUi',
875+
),
876+
).toMatchInlineSnapshot(`
877+
Object {
878+
"subscriptions": Array [],
879+
}
880+
`);
881+
});
882+
});
883+
});
822884
});

packages/subscription-controller/src/SubscriptionController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ export function getDefaultSubscriptionControllerState(): SubscriptionControllerS
133133
const subscriptionControllerMetadata: StateMetadata<SubscriptionControllerState> =
134134
{
135135
subscriptions: {
136+
includeInStateLogs: true,
136137
persist: true,
137138
anonymous: false,
139+
usedInUi: true,
138140
},
139141
};
140142

0 commit comments

Comments
 (0)