Skip to content
Permalink
Browse files

fix login race condition issues

  • Loading branch information...
pozylon committed May 11, 2019
1 parent 9c446b0 commit 1f99897d9c9d93b9c231c4b89bd5c9f9047fe1c5
Showing with 40 additions and 5 deletions.
  1. +21 −4 tests/auth-anonymous.test.js
  2. +1 −1 tests/auth-user.test.js
  3. +18 −0 tests/cart-checkout.test.js
@@ -1,4 +1,5 @@
import { setupDatabase, createAnonymousGraphqlFetch } from './helpers';
import { User } from './seeds/users';

let connection;
let db;
@@ -35,11 +36,25 @@ describe('Auth for anonymous users', () => {
describe('Mutation.forgotPassword', () => {
let token;

beforeAll(async () => {
const Users = db.collection('users');
await Users.findOrInsertOne({
...User,
_id: 'userthatforgetspasswords',
emails: [
{
address: 'userthatforgetspasswords@localhost',
verified: true
}
]
});
});

it('create a reset token', async () => {
const { data: { forgotPassword } = {} } = await graphqlFetch({
query: /* GraphQL */ `
mutation {
forgotPassword(email: "user@localhost") {
forgotPassword(email: "userthatforgetspasswords@localhost") {
success
}
}
@@ -51,7 +66,9 @@ describe('Auth for anonymous users', () => {

// Get the token which is sent via E-Mail
const Users = db.collection('users');
const user = await Users.findOne({ 'emails.address': 'user@localhost' });
const user = await Users.findOne({
'emails.address': 'userthatforgetspasswords@localhost'
});
({
services: {
password: {
@@ -81,9 +98,9 @@ describe('Auth for anonymous users', () => {
}
});
expect(resetPassword).toMatchObject({
id: 'user',
id: 'userthatforgetspasswords',
user: {
_id: 'user'
_id: 'userthatforgetspasswords'
}
});
});
@@ -5,7 +5,7 @@ let connection;
let db;
let graphqlFetch;

describe('auth for logged in users', () => {
describe('Auth for logged in users', () => {
beforeAll(async () => {
[db, connection] = await setupDatabase();
graphqlFetch = await createLoggedInGraphqlFetch(USER_TOKEN);
@@ -13,4 +13,22 @@ describe('cart checkout', () => {
afterAll(async () => {
await connection.close();
});

describe('Mutation.createCart', () => {
it('create a cart with a specific order number', async () => {
const { data: { createCart } = {} } = await graphqlFetch({
query: /* GraphQL */ `
mutation {
createCart(orderNumber: "wishlist") {
_id
orderNumber
}
}
`
});
expect(createCart).toMatchObject({
orderNumber: 'wishlist'
});
});
});
});

0 comments on commit 1f99897

Please sign in to comment.
You can’t perform that action at this time.