Skip to content

Commit 43d512b

Browse files
committed
fix: remaining tests
1 parent fbd84b8 commit 43d512b

File tree

42 files changed

+141
-2156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+141
-2156
lines changed

modules/core/__tests__/index.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1+
import 'reflect-metadata';
12
import { print } from 'graphql';
23
import { createApplication } from 'graphql-modules';
34
import { createAccountsCoreModule } from '../src';
45
import { mergeTypeDefs } from '@graphql-tools/merge';
5-
6-
const accountsServer = {
7-
getServices: () => ({
8-
password: {},
9-
magicLink: {},
10-
}),
11-
};
6+
import {
7+
AuthenticationServicesToken,
8+
DatabaseInterfaceSessionsToken,
9+
DatabaseInterfaceUserToken,
10+
} from '@accounts/server';
1211

1312
describe('AccountsModule', () => {
1413
it('should export typeDefs with schema definition', () => {
1514
const accountsGraphQL = createApplication({
16-
modules: [createAccountsCoreModule({ accountsServer } as any)],
15+
modules: [createAccountsCoreModule({ tokenSecret: 'random' })],
16+
providers: [
17+
{
18+
provide: AuthenticationServicesToken,
19+
useValue: {
20+
password: {
21+
setUserStore: () => null,
22+
setSessionsStore: () => null,
23+
},
24+
},
25+
global: true,
26+
},
27+
{
28+
provide: DatabaseInterfaceUserToken,
29+
useValue: {},
30+
global: true,
31+
},
32+
{
33+
provide: DatabaseInterfaceSessionsToken,
34+
useValue: undefined,
35+
global: true,
36+
},
37+
],
1738
});
1839
expect(print(mergeTypeDefs(accountsGraphQL.typeDefs))).toMatch(/schema/);
1940
});

modules/core/__tests__/resolvers/mutation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'reflect-metadata';
12
import { AccountsServer } from '@accounts/server';
23
import { Mutation } from '../../src/resolvers/mutation';
34

modules/core/__tests__/utils/context-builder.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
import 'reflect-metadata';
12
import { context } from '../../src/utils/context-builder';
23

34
describe('context-builder', () => {
45
const user = { id: 'idTest' };
56
const accountsServerMock = {
67
resumeSession: jest.fn<any, any>(() => user),
78
};
9+
const controllerMock = {
10+
injector: {
11+
get: jest.fn(() => accountsServerMock),
12+
},
13+
};
14+
const appMock = {
15+
createOperationController: jest.fn(() => controllerMock),
16+
};
817
const authToken = 'authTokenTest';
918
const ip = '0.0.0.0';
1019
const reqMock = {
@@ -20,23 +29,20 @@ describe('context-builder', () => {
2029

2130
it('should not resume session is header is empty', async () => {
2231
accountsServerMock.resumeSession.mockRejectedValueOnce(true);
23-
await context({ req: { headers: {} } } as any, { accountsServer: accountsServerMock } as any);
32+
await context({ req: { headers: {} } } as any, { app: appMock } as any);
2433
expect(accountsServerMock.resumeSession).not.toHaveBeenCalled();
2534
});
2635

2736
it('should resume session and inject the user', async () => {
2837
accountsServerMock.resumeSession.mockRejectedValueOnce(true);
29-
const data = await context(
30-
{ req: reqMock } as any,
31-
{ accountsServer: accountsServerMock } as any
32-
);
38+
const data = await context({ req: reqMock } as any, { app: appMock } as any);
3339
expect(accountsServerMock.resumeSession).toHaveBeenCalledWith(authToken);
3440
expect(data.authToken).toBe(authToken);
3541
expect(data.ip).toBe(ip);
3642
});
3743

3844
it('should allow no request in context', async () => {
39-
const data = await context({} as any, { accountsServer: accountsServerMock } as any);
45+
const data = await context({} as any, { app: appMock } as any);
4046
expect(data.ip).toBe('');
4147
expect(data.userAgent).toBe('');
4248
expect(accountsServerMock.resumeSession).not.toHaveBeenCalled();

modules/magic-link/__tests__/resolvers/mutation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'reflect-metadata';
12
import { AccountsJsError } from '@accounts/server';
23
import { AccountsMagicLink, RequestMagicLinkEmailErrors } from '@accounts/magic-link';
34
import { Mutation } from '../../src/resolvers/mutation';

modules/mikro-orm/__tests__/modules/accounts-magic-link/resolvers/mutation.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)