From c7f832e883d1cca6ccaa80c241a663ab0e113f45 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Fri, 29 Nov 2024 21:12:41 +0530 Subject: [PATCH] test: added test for browser auth open Signed-off-by: Abinand P --- tests/lib/auth.test.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/lib/auth.test.ts b/tests/lib/auth.test.ts index 9d94504..c1e1d8e 100644 --- a/tests/lib/auth.test.ts +++ b/tests/lib/auth.test.ts @@ -1,17 +1,18 @@ import { describe, vi, it, expect } from 'vitest'; import * as auth from '../../source/lib/auth'; import pkg from 'keytar'; -import delay from 'delay'; +import * as http from 'http'; import { KEYSTORE_PERMIT_SERVICE_NAME, DEFAULT_PERMIT_KEYSTORE_ACCOUNT, } from '../../source/config'; -import http from 'http'; import open from 'open'; -import { randomBytes, createHash } from 'crypto'; -vi.mock('node:http', () => ({ - createServer: vi.fn(), +vi.mock('http', () => ({ + createServer: vi.fn().mockReturnValue({ + listen: vi.fn(), + close: vi.fn(), + }), })); vi.mock('open', () => ({ default: vi.fn(), @@ -25,8 +26,6 @@ vi.mock('node:crypto', () => ({ })), })); -global.fetch = vi.fn(); - describe('Token Type', () => { it('Should return correct token type', async () => { const demoToken = 'permit_key_'.concat('a'.repeat(97)); @@ -86,3 +85,9 @@ describe('Clean Auth Token', () => { expect(result).toBeNull(); }); }); +describe('Browser Auth', () => { + it('Should open browser', async () => { + await auth.browserAuth(); + expect(open).toHaveBeenCalled(); + }); +});