Skip to content

Add authentication test helpers #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a2c428b
Fix check for skipped items
Oct 5, 2018
fa7022c
Merge pull request #1 from SpicyWeb-de/fix-skippedItems
Oct 5, 2018
6c995d7
Merge branch 'master' into stable
larixer Nov 2, 2018
2bacc66
Merge branch 'master' into stable
larixer Nov 2, 2018
e3cdb0f
Merge branch 'master' into stable
larixer Mar 6, 2019
86b7363
Merge branch 'master' into stable
larixer Mar 19, 2019
65fa9c8
Add new scripts
AndSviat Feb 25, 2019
6411e31
Add information about enabling symlinks in Windows 10
AndSviat Mar 19, 2019
66beac2
Fix #1048 mobile builds not work under Windows
larixer Mar 20, 2019
d8bcbcc
Merge branch 'master' into stable
larixer Mar 21, 2019
f84577a
Merge branch 'master' into stable
larixer Mar 21, 2019
eff650f
Merge branch 'master' into stable
larixer Mar 23, 2019
95d7946
Merge branch 'master' into stable
larixer Mar 23, 2019
94dcdaa
Write full company
larixer Apr 11, 2019
c6f3ec7
Merge branch 'master' into stable
larixer Apr 24, 2019
a7d2bb1
Merge branch 'master' into stable
larixer Apr 24, 2019
7e733ef
Merge branch 'master' into stable
larixer Apr 24, 2019
a63dddc
Merge remote-tracking branch 'origin/master' into stable
larixer Apr 29, 2019
e79d397
Merge branch 'master' into stable
larixer Apr 29, 2019
b0372b3
Merge branch 'master' into stable
larixer Apr 30, 2019
24368f1
Merge branch 'master' into stable
larixer May 19, 2019
de573f9
Rename docs for consistency and update links accordingly (#1085)
AndSviat May 21, 2019
d9beada
Remove regenerator plugin
larixer May 21, 2019
f31ad31
More exhaustive hook checks in eslint
larixer May 21, 2019
48078b5
Fix mounting error in Chat screen. (#1086)
Undeadlol1 May 22, 2019
48bcae1
Add opencollective settings
larixer May 27, 2019
84f4961
Fix name DB_TYPE->DB_CLIENT
larixer May 30, 2019
0aa25a5
Fix problem with REST not being enabled
larixer May 30, 2019
3ec3793
Make createApp async (#1091)
larixer Jun 3, 2019
3cfc36b
Update Travis build badge
larixer Jun 4, 2019
67d8e21
Add React Storybook integration
larixer Jun 5, 2019
c16bfce
Add initial CDN support
larixer Jun 6, 2019
70e8b57
Upgrade to Expo SDK 33
larixer Jun 7, 2019
744ea58
fix "FAQ" link in readme
Undeadlol1 Jun 8, 2019
d239813
Fix storybook support
larixer Jun 11, 2019
f835ef1
Switch to webpack.config.js for building artifacts (#1100)
larixer Jun 12, 2019
a05e370
Build only server client and mobile
larixer Jun 12, 2019
85e3d53
Improve travis conf
larixer Jun 12, 2019
6dee31a
Remove heroku-postbuild from angular and vue
larixer Jun 12, 2019
0704f6c
Add watch-server yarn script
verdverm Jun 12, 2019
62de198
Heroku&Travis optimizations
larixer Jun 13, 2019
5648da1
Switch to vanilla Expo build scripts (#1105)
larixer Jun 13, 2019
6067edb
Safely escape build.config.js values
larixer Jun 15, 2019
f5bd781
Fix __SSR__ definition
larixer Jun 15, 2019
2c93d42
Fix ForOfStatement issue
larixer Jun 17, 2019
4cc4bd8
Fix storybook watching issue
larixer Jun 17, 2019
ff7db98
Return .graphql files for schema on backend (#1109)
larixer Jun 17, 2019
5f7f421
Update docs, remove zen, make relative URLs (#1110)
larixer Jun 17, 2019
b945345
Use BACKEND_API_URL env var for backend
larixer Jun 17, 2019
f139839
Use compression for Express
larixer Jun 17, 2019
3bdde7b
Add client-side and server-side code splitting for React stack (#1098)
larixer Jun 17, 2019
686ea41
Merge with latest master
larixer Jun 20, 2019
5ce1338
Merge branch 'master' into stable
larixer Jun 26, 2019
a6c4968
Merge branch 'master' into stable
larixer Jun 27, 2019
2eaa0f9
Merge branch 'master' into stable
larixer Jun 28, 2019
d92a419
Merge remote-tracking branch 'upstream/stable'
qroac Jul 22, 2019
692ae86
Adds authentication test helpers
qroac Jul 22, 2019
d477733
Adds Tests for authentication helpers and rewrites user module tests …
qroac Jul 22, 2019
9b491c4
Force jest to run server tests in one thread
qroac Jul 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { expect } from 'chai';
import { ApolloClient } from 'apollo-client';

import { getApollo } from '@gqlapp/testing-server-ts';
import CURRENT_USER_QUERY from '@gqlapp/user-client-react/graphql/CurrentUserQuery.graphql';

import { login, logout } from '../test-helpers';

describe('TestHelpers for authentication work', () => {
let apollo: ApolloClient<any>;

beforeAll(() => {
apollo = getApollo();
});

test('User not logged in initially', async () => {
const result = await apollo.query({ query: CURRENT_USER_QUERY });
expect(result.data).to.deep.equal({ currentUser: null });
});

test('Signing in as ordinary user works', async () => {
await login('user', 'user1234');
const result = await apollo.query({ query: CURRENT_USER_QUERY });
expect(result.data.currentUser.username).to.equal('user');
});

test('Signing out as ordinary user works', async () => {
await logout();
const result = await apollo.query({ query: CURRENT_USER_QUERY });
expect(result.data).to.deep.equal({ currentUser: null });
});

test('Signing in without parameters as admin works', async () => {
await login();
const result = await apollo.query({ query: CURRENT_USER_QUERY });
expect(result.data.currentUser.username).to.equal('admin');
await logout();
});
});
3 changes: 2 additions & 1 deletion modules/authentication/server-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ServerModule from '@gqlapp/module-server-ts';
import AuthModule from './social/AuthModule';
import access from './access';
import social from './social';
import * as TestHelper from './test-helpers';

export default new ServerModule(access, social);
export { access, AuthModule };
export { access, AuthModule, TestHelper };
11 changes: 11 additions & 0 deletions modules/authentication/server-ts/test-helpers/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getApollo } from '@gqlapp/testing-server-ts';
import LOGIN from '@gqlapp/user-client-react/graphql/Login.graphql';
import LOGOUT from '@gqlapp/authentication-client-react/access/session/graphql/Logout.graphql';

export const login = async (usernameOrEmail: string = 'admin', password: string = 'admin123') =>
getApollo().mutate({
mutation: LOGIN,
variables: { input: { usernameOrEmail, password } }
});

export const logout = async () => getApollo().mutate({ mutation: LOGOUT });
1 change: 1 addition & 0 deletions modules/authentication/server-ts/test-helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './authentication';
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import chai, { expect } from 'chai';
import CURRENT_USER_QUERY from '@gqlapp/user-client-react/graphql/CurrentUserQuery.graphql';
import USER_QUERY from '@gqlapp/user-client-react/graphql/UserQuery.graphql';
import { getApollo } from '@gqlapp/testing-server-ts';

import { login, logout } from '../testHelpers';
import { TestHelper as AuthHelper } from '@gqlapp/authentication-server-ts';

describe('User API works', () => {
let apollo: any;
Expand All @@ -19,13 +18,13 @@ describe('User API works', () => {
});

it('Signing in as ordinary user works', async () => {
await login('user', 'user1234');
await AuthHelper.login('user', 'user1234');
const result = await apollo.query({ query: CURRENT_USER_QUERY });
expect(result.data.currentUser.username).to.equal('user');
});

it('Signing out as ordinary user works', async () => {
await logout();
await AuthHelper.logout();
const result = await apollo.query({ query: CURRENT_USER_QUERY });
expect(result.data).to.deep.equal({ currentUser: null });
});
Expand All @@ -50,10 +49,10 @@ describe('User API works', () => {

describe('Tests with authenticated user', () => {
beforeEach(async () => {
await login('user', 'user1234');
await AuthHelper.login('user', 'user1234');
});
afterEach(async () => {
await logout();
await AuthHelper.logout();
});

it('Can query own user profile', async () => {
Expand All @@ -72,10 +71,10 @@ describe('User API works', () => {

describe('Tests with authenticated admin', () => {
beforeEach(async () => {
await login('admin', 'admin123');
await AuthHelper.login('admin', 'admin123');
});
afterEach(async () => {
await logout();
await AuthHelper.logout();
});

it('Can query own user profile', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"clean": "rimraf build .tmp",
"start": "node --harmony build",
"test": "yarn tests && yarn lint",
"tests": "cross-env PORT=7070 jest --forceExit",
"tests:watch": "cross-env PORT=7070 jest --watch",
"tests": "cross-env PORT=7070 jest --runInBand --forceExit",
"tests:watch": "cross-env PORT=7070 jest --runInBand --watch",
"eslint": "eslint --fix --ext js --ext jsx --ext json src",
"tslint": "tslint --fix -p ../../tsconfig.json -c ../../tslint.json",
"lint": "yarn eslint && yarn tslint",
Expand Down