Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Revert "Revert "test(unit): converted the gh-client-factory tests to …
Browse files Browse the repository at this point in the history
…vitest""

This reverts commit 5bca961.
  • Loading branch information
travi committed Apr 12, 2023
1 parent 17e16e9 commit 1949f8e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
41 changes: 0 additions & 41 deletions src/github-client-factory-test.js

This file was deleted.

42 changes: 42 additions & 0 deletions src/github-client-factory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as octokit from '@octokit/rest';
import {createNetrcAuth} from 'octokit-auth-netrc';

import {afterEach, describe, expect, it, vi} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

import {factory} from './github-client-factory';

vi.mock('@octokit/rest');

describe('github client factory', () => {
afterEach(() => {
vi.clearAllMocks();
});

it('should authenticate the client using the token from netrc', () => {
const instance = any.simpleObject();
when(octokit.Octokit).calledWith({authStrategy: createNetrcAuth}).mockReturnValue(instance);

expect(factory()).toBe(instance);
});

it('should not return a client if no token is available in the netrc', () => {
const error = new Error('from test');
error.code = 'ENONETRCTOKEN';
octokit.Octokit.mockImplementation(() => {
throw error;
});

expect(factory()).toBeUndefined();
});

it('should rethrow an error that is unrelated to a missing netrc token', () => {
const error = new Error('from test');
octokit.Octokit.mockImplementation(() => {
throw error;
});

expect(() => factory()).toThrowError(error);
});
});

0 comments on commit 1949f8e

Please sign in to comment.