Skip to content

Commit

Permalink
Update ChromeWindowsCookieProvider.unit.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalininator committed Nov 1, 2021
1 parent f85d699 commit e67a92c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/chrome/ChromeWindowsCookieProvider.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,56 @@ describe('chrome windows cookie provider', () => {

expect(mockFindCookie).toHaveBeenCalledWith('some_cookie', '.test.com');
});

it('should return undefined if cookie not found', async () => {
const mockFindCookie = jest.fn().mockReturnValue(undefined);
const mockDb: ChromeCookieRepository = {
findCookie: mockFindCookie,
listCookies(): ChromeCookie[] {
throw new Error('Function not implemented.');
},
};

const provider = new ChromeWindowsCookieProvider(mockDb);

const cookie = await provider.getCookie('.test.com', 'some_cookie');

expect(cookie).toEqual(undefined);

expect(mockFindCookie).toHaveBeenCalledWith('some_cookie', '.test.com');
});

it('should list and decrypt cookies', async () => {
const mockListCookies = jest.fn().mockImplementation((): ChromeCookie[] => {
return [
{
host_key: '.some.url',
path: '/',
name: 'someCookie',
encrypted_value: fakeBuffer,
},
];
});
const mockDb: ChromeCookieRepository = {
findCookie() {
throw new Error('function not implemented');
},
listCookies: mockListCookies,
};

const provider = new ChromeWindowsCookieProvider(mockDb);

const cookies = await provider.listCookies();

expect(cookies).toEqual([
{
value: 'foo',
host: '.some.url',
path: '/',
name: 'someCookie',
},
]);

expect(mockListCookies).toHaveBeenCalledWith();
});
});

0 comments on commit e67a92c

Please sign in to comment.