Skip to content

Commit

Permalink
Put nock in describe to fix console.log errors
Browse files Browse the repository at this point in the history
Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
  • Loading branch information
segun committed Nov 25, 2022
1 parent 3925c4a commit 660f0c8
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions packages/phishing-controller/src/PhishingController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,31 @@ describe('PhishingController', () => {
});

describe('maybeUpdatePhishingLists', () => {
let nockScope: nock.Scope;

beforeEach(() => {
nockScope = nock(PHISHING_CONFIG_BASE_URL)
.get(METAMASK_CONFIG_FILE)
.reply(200, {
blacklist: ['this-should-not-be-in-default-blacklist.com'],
fuzzylist: [],
tolerance: 0,
whitelist: ['this-should-not-be-in-default-whitelist.com'],
version: 0,
})
.get(PHISHFORT_HOTLIST_FILE)
.reply(200, []);
});

it('should not be out of date immediately after maybeUpdatePhishingLists is called', async () => {
const clock = sinon.useFakeTimers();
const controller = new PhishingController({ refreshInterval: 10 });
clock.tick(10);
expect(controller.isOutOfDate()).toBe(true);
await controller.maybeUpdatePhishingLists();
expect(controller.isOutOfDate()).toBe(false);

expect(nockScope.isDone()).toBe(true);
});

it('should not be out of date after maybeUpdatePhishingLists is called but before refresh interval has passed', async () => {
Expand All @@ -87,6 +105,7 @@ describe('PhishingController', () => {
await controller.maybeUpdatePhishingLists();
clock.tick(5);
expect(controller.isOutOfDate()).toBe(false);
expect(nockScope.isDone()).toBe(true);
});

it('should still be out of date while update is in progress', async () => {
Expand All @@ -101,20 +120,10 @@ describe('PhishingController', () => {
expect(controller.isOutOfDate()).toBe(false);
clock.tick(10);
expect(controller.isOutOfDate()).toBe(true);
expect(nockScope.isDone()).toBe(true);
});

it('should call update only if it is out of date, otherwise it should not call update', async () => {
nock(PHISHING_CONFIG_BASE_URL)
.get(METAMASK_CONFIG_FILE)
.reply(200, {
blacklist: ['this-should-not-be-in-default-blacklist.com'],
fuzzylist: [],
tolerance: 0,
whitelist: ['this-should-not-be-in-default-whitelist.com'],
version: 0,
})
.get(PHISHFORT_HOTLIST_FILE)
.reply(200, []);
const clock = sinon.useFakeTimers();
const controller = new PhishingController({ refreshInterval: 10 });
expect(controller.isOutOfDate()).toBe(false);
Expand Down Expand Up @@ -149,6 +158,8 @@ describe('PhishingController', () => {
result: false,
type: 'allowlist',
});

expect(nockScope.isDone()).toBe(true);
});
});

Expand Down

0 comments on commit 660f0c8

Please sign in to comment.