Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Nov 30, 2021
1 parent fe83e67 commit 69634ba
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ComposableController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ describe('ComposableController', () => {
selectedAddress: '',
useStaticTokenList: false,
useCollectibleDetection: false,
openSeaEnabled: false,
},
});
});
Expand Down Expand Up @@ -236,6 +237,7 @@ describe('ComposableController', () => {
selectedAddress: '',
useStaticTokenList: false,
useCollectibleDetection: false,
openSeaEnabled: false,
suggestedAssets: [],
tokens: [],
});
Expand Down
11 changes: 11 additions & 0 deletions src/assets/CollectibleDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('CollectibleDetectionController', () => {
getCollectiblesState: () => collectiblesController.state,
});

preferences.setOpenSeaEnabled(true);
preferences.setUseCollectibleDetection(true);

nock(OPEN_SEA_HOST)
Expand Down Expand Up @@ -376,6 +377,16 @@ describe('CollectibleDetectionController', () => {
expect(collectiblesController.state.collectibles).toStrictEqual([]);
});

it('should not detect and add collectibles if preferences controller openSeaEnabled is set to false', async () => {
preferences.setOpenSeaEnabled(false);
collectibleDetection.configure({
networkType: MAINNET,
selectedAddress: '0x9',
});
collectibleDetection.detectCollectibles();
expect(collectiblesController.state.collectibles).toStrictEqual([]);
});

it('should not add collectible if collectible or collectible contract has no information to display', async () => {
const collectibleHH2574 = {
address: '0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD',
Expand Down
5 changes: 4 additions & 1 deletion src/assets/CollectiblesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ describe('CollectiblesController', () => {
),
});

preferences.update({ selectedAddress: OWNER_ADDRESS });
preferences.update({
selectedAddress: OWNER_ADDRESS,
openSeaEnabled: true,
});

sandbox
.stub(collectiblesController, 'isCollectibleOwner' as any)
Expand Down
2 changes: 2 additions & 0 deletions src/user/PreferencesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('PreferencesController', () => {
selectedAddress: '',
useStaticTokenList: false,
useCollectibleDetection: false,
openSeaEnabled: false,
});
});

Expand Down Expand Up @@ -220,6 +221,7 @@ describe('PreferencesController', () => {

it('should set useCollectibleDetection', () => {
const controller = new PreferencesController();
controller.setOpenSeaEnabled(true);
controller.setUseCollectibleDetection(true);
expect(controller.state.useCollectibleDetection).toStrictEqual(true);
});
Expand Down
5 changes: 5 additions & 0 deletions src/user/PreferencesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ export class PreferencesController extends BaseController<
* @param useCollectibleDetection - Boolean indicating user preference on collectible detection.
*/
setUseCollectibleDetection(useCollectibleDetection: boolean) {
if (useCollectibleDetection && !this.state.openSeaEnabled) {
throw new Error(
'useCollectibleDetection cannot be enabled if openSeaEnabled is false',
);
}
this.update({ useCollectibleDetection });
}

Expand Down

0 comments on commit 69634ba

Please sign in to comment.