|
| 1 | +jest.mock('googleapis') |
| 2 | +import { google } from 'googleapis' |
1 | 3 | import * as mod from '../src/google' |
2 | 4 |
|
| 5 | +const fakeUsersResponse = [ |
| 6 | + { customSchemas: { Accounts: { github: [{ value: 'chrisns' }] } } }, |
| 7 | + { |
| 8 | + customSchemas: { |
| 9 | + Accounts: { github: [{ value: 'Foo' }, , { value: 'tar' }] }, |
| 10 | + }, |
| 11 | + }, |
| 12 | + { |
| 13 | + customSchemas: { |
| 14 | + Accounts: { github: [{ value: 'foo' }, { value: 'bar' }] }, |
| 15 | + }, |
| 16 | + }, |
| 17 | +] |
| 18 | + |
3 | 19 | describe('google integration', () => { |
4 | | - it.todo('googleAuth') |
5 | | - it.skip('getAdminService', () => { |
| 20 | + beforeEach(() => { |
| 21 | + process.env.GOOGLE_EMAIL_ADDRESS = 'hello@example.com' |
| 22 | + process.env.GOOGLE_CREDENTIALS = Buffer.from(JSON.stringify({ client_email: 'foo', private_key: 'bar' })).toString( |
| 23 | + 'base64', |
| 24 | + ) |
| 25 | + jest.resetAllMocks() |
| 26 | + }) |
| 27 | + it('googleAuth', () => { |
| 28 | + mod.googleAuth() |
| 29 | + // @ts-expect-error .mocks isn't on the original object so will fail |
| 30 | + return expect(google.auth.JWT.mock.calls).toMatchSnapshot() |
| 31 | + }) |
| 32 | + it('getAdminService', () => { |
| 33 | + // @ts-expect-error mock service isn't a complete implementation, so being lazy and just doing the bare minimum |
| 34 | + google.admin.mockReturnValue('adminservice') |
6 | 35 | const result = mod.getAdminService() |
7 | | - return expect(result).resolves.toBe({}) |
| 36 | + return expect(result).resolves.toBe('adminservice') |
8 | 37 | }) |
9 | 38 |
|
10 | | - it.todo('getGithubUsersFromGoogle') |
| 39 | + it('getGithubUsersFromGoogle', () => { |
| 40 | + const service = { users: { list: jest.fn().mockResolvedValue({ data: { users: fakeUsersResponse } }) } } |
| 41 | + // @ts-expect-error mock service isn't a complete implementation, so being lazy and just doing the bare minimum |
| 42 | + jest.spyOn(mod, 'getAdminService').mockResolvedValue(service) |
11 | 43 |
|
12 | | - it('formatUserList', () => { |
13 | | - const response = [ |
14 | | - { customSchemas: { Accounts: { github: [{ value: 'chrisns' }] } } }, |
15 | | - { |
16 | | - customSchemas: { |
17 | | - Accounts: { github: [{ value: 'Foo' }, , { value: 'tar' }] }, |
18 | | - }, |
19 | | - }, |
20 | | - { |
21 | | - customSchemas: { |
22 | | - Accounts: { github: [{ value: 'foo' }, { value: 'bar' }] }, |
23 | | - }, |
24 | | - }, |
25 | | - ] |
26 | | - return expect(mod.formatUserList(response)).toEqual(new Set(['chrisns', 'foo', 'bar', 'tar'])) |
| 44 | + const result = mod.getGithubUsersFromGoogle() |
| 45 | + expect(result).resolves.toMatchSnapshot() |
27 | 46 | }) |
| 47 | + |
| 48 | + it('formatUserList', () => |
| 49 | + expect(mod.formatUserList(fakeUsersResponse)).toEqual(new Set(['chrisns', 'foo', 'bar', 'tar']))) |
28 | 50 | }) |
0 commit comments