Skip to content

Commit

Permalink
Add google auth mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Blyszcz committed Aug 29, 2018
1 parent 5d0b6e5 commit 86347fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 52 deletions.
70 changes: 18 additions & 52 deletions src/services/cli/fileGenerators.spec.ts
@@ -1,11 +1,25 @@
import * as awilix from 'awilix';
import { generateTranslations, generateEnvConfigFile, generateJsonConfigFile } from './fileGenerators';
import createContainer from './container';
import GoogleSheets from '../../shared/google/sheets';
import { ITransformers } from '../../shared/transformers/transformers.types';
import { getGoogleAuthMock } from '../../tests/googleAuthMock';

export const getExtension = jest.fn();

const args = {
_: ['test', 'test2'],
$0: 'test',
format: 'json',
client_id: 'test',
client_secret: 'test2',
spreadsheet_id: 'test3',
spreadsheet_name: 'test4',
path: '.',
language: 'test-lang',
merge: false,
filename: 'test-filename',
};

describe('fileGenerators', async () => {
it('generateTranslations does run proper functions', async () => {
const mockGoogleSheets = {
Expand All @@ -25,19 +39,7 @@ describe('fileGenerators', async () => {
transformers: awilix.asValue(mockTransformers),
filesCreators: awilix.asValue(mockFileCreators),
});
const args = {
_: ['test', 'test2'],
$0: 'test',
format: 'json',
client_id: 'test',
client_secret: 'test2',
spreadsheet_id: 'test3',
spreadsheet_name: 'test4',
path: '.',
language: 'test-lang',
merge: false,
filename: 'test-filename',
};

await generateTranslations(container, args);

expect(mockGoogleSheets.fetchSpreadsheet).toBeCalled();
Expand All @@ -50,28 +52,10 @@ describe('fileGenerators', async () => {
set: jest.fn(),
};

const mockGoogleAuth = {
createOAuthClient: jest.fn(),
getTokens: jest.fn().mockImplementation(() => ({ refresh_token: 'test-token' })),
};

const container = createContainer().register({
inEnvStorage: awilix.asValue(mockInEnvStorage),
googleAuth: awilix.asValue(mockGoogleAuth),
googleAuth: awilix.asValue(getGoogleAuthMock()),
});
const args = {
_: ['test', 'test2'],
$0: 'test',
format: 'json',
client_id: 'test',
client_secret: 'test2',
spreadsheet_id: 'test3',
spreadsheet_name: 'test4',
path: '.',
language: 'test-lang',
merge: false,
filename: 'test-filename',
};

await generateEnvConfigFile(container, args);

Expand All @@ -83,28 +67,10 @@ describe('fileGenerators', async () => {
set: jest.fn(),
};

const mockGoogleAuth = {
createOAuthClient: jest.fn(),
getTokens: jest.fn().mockImplementation(() => ({ refresh_token: 'test-token' })),
};

const container = createContainer().register({
inFileStorage: awilix.asValue(mockInFileStorage),
googleAuth: awilix.asValue(mockGoogleAuth),
googleAuth: awilix.asValue(getGoogleAuthMock()),
});
const args = {
_: ['test', 'test2'],
$0: 'test',
format: 'json',
client_id: 'test',
client_secret: 'test2',
spreadsheet_id: 'test3',
spreadsheet_name: 'test4',
path: '.',
language: 'test-lang',
merge: false,
filename: 'test-filename',
};

await generateJsonConfigFile(container, args);

Expand Down
6 changes: 6 additions & 0 deletions src/tests/googleAuthMock.ts
@@ -0,0 +1,6 @@
const googleAuthMock = {
createOAuthClient: jest.fn(),
getTokens: jest.fn().mockImplementation(() => ({ refresh_token: 'test-token' })),
};

export const getGoogleAuthMock = () => googleAuthMock;

0 comments on commit 86347fe

Please sign in to comment.