Skip to content

Commit

Permalink
test: added test for browser auth open
Browse files Browse the repository at this point in the history
Signed-off-by: Abinand P <[email protected]>
  • Loading branch information
Abiji-2020 committed Nov 29, 2024
1 parent 0a02058 commit c7f832e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/lib/auth.test.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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));
Expand Down Expand Up @@ -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();
});
});

0 comments on commit c7f832e

Please sign in to comment.