|
|
@ -11,31 +11,11 @@ import { AccessToken } from "./userResolver/AccessToken" |
|
|
|
import { Context, signAccessToken, verifiedAccessTokenPayload } from "./userResolver/auth" |
|
|
|
import { Context, signAccessToken, verifiedAccessTokenPayload } from "./userResolver/auth" |
|
|
|
import { User } from "./userResolver/User" |
|
|
|
import { User } from "./userResolver/User" |
|
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => { |
|
|
|
|
|
|
|
initializeRollbackTransactions() |
|
|
|
|
|
|
|
await createConnection(testingConnectionOptions()) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
afterAll(async () => { |
|
|
|
|
|
|
|
await getConnection().close() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe("resolver of user", () => { |
|
|
|
describe("resolver of user", () => { |
|
|
|
describe("createUser mutation should", () => { |
|
|
|
describe("createUser mutation should", () => { |
|
|
|
it( |
|
|
|
it( |
|
|
|
"return email as it creates user with mutation", |
|
|
|
"return email as it creates user with mutation", |
|
|
|
runInRollbackTransaction(async () => { |
|
|
|
runInRollbackTransaction(async () => { |
|
|
|
const createUserMutation = gql` |
|
|
|
|
|
|
|
mutation { |
|
|
|
|
|
|
|
createUser( |
|
|
|
|
|
|
|
email: "user-mutation@user-resolver.com" |
|
|
|
|
|
|
|
password: "password" |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
email |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const response = await callSchema(createUserMutation) |
|
|
|
const response = await callSchema(createUserMutation) |
|
|
|
|
|
|
|
|
|
|
|
expect(response.errors).toBeUndefined() |
|
|
|
expect(response.errors).toBeUndefined() |
|
|
@ -50,14 +30,6 @@ describe("resolver of user", () => { |
|
|
|
it( |
|
|
|
it( |
|
|
|
"return emails of registered users", |
|
|
|
"return emails of registered users", |
|
|
|
runInRollbackTransaction(async () => { |
|
|
|
runInRollbackTransaction(async () => { |
|
|
|
const usersQuery = gql` |
|
|
|
|
|
|
|
query { |
|
|
|
|
|
|
|
users { |
|
|
|
|
|
|
|
email |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await User.create({ |
|
|
|
await User.create({ |
|
|
|
email: "users-query@user-resolver.com", |
|
|
|
email: "users-query@user-resolver.com", |
|
|
|
}).save() |
|
|
|
}).save() |
|
|
@ -73,18 +45,6 @@ describe("resolver of user", () => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe("accessToken query should", () => { |
|
|
|
describe("accessToken query should", () => { |
|
|
|
const accessTokenQuery = gql` |
|
|
|
|
|
|
|
query { |
|
|
|
|
|
|
|
accessToken( |
|
|
|
|
|
|
|
email: "access-token@user-resolver.com" |
|
|
|
|
|
|
|
password: "password" |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
jwt |
|
|
|
|
|
|
|
jwtExpiry |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it( |
|
|
|
it( |
|
|
|
"return error for bad password or not-existent user", |
|
|
|
"return error for bad password or not-existent user", |
|
|
|
runInRollbackTransaction(async () => { |
|
|
|
runInRollbackTransaction(async () => { |
|
|
@ -126,14 +86,6 @@ describe("resolver of user", () => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe("me query should", () => { |
|
|
|
describe("me query should", () => { |
|
|
|
const meQuery = gql` |
|
|
|
|
|
|
|
query { |
|
|
|
|
|
|
|
me { |
|
|
|
|
|
|
|
email |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it( |
|
|
|
it( |
|
|
|
"return an error without a valid access token", |
|
|
|
"return an error without a valid access token", |
|
|
|
runInRollbackTransaction(async () => { |
|
|
|
runInRollbackTransaction(async () => { |
|
|
@ -168,6 +120,45 @@ describe("resolver of user", () => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => { |
|
|
|
|
|
|
|
initializeRollbackTransactions() |
|
|
|
|
|
|
|
await createConnection(testingConnectionOptions()) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
afterAll(async () => { |
|
|
|
|
|
|
|
await getConnection().close() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const createUserMutation = gql` |
|
|
|
|
|
|
|
mutation { |
|
|
|
|
|
|
|
createUser(email: "user-mutation@user-resolver.com", password: "password") { |
|
|
|
|
|
|
|
email |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
const usersQuery = gql` |
|
|
|
|
|
|
|
query { |
|
|
|
|
|
|
|
users { |
|
|
|
|
|
|
|
email |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
const accessTokenQuery = gql` |
|
|
|
|
|
|
|
query { |
|
|
|
|
|
|
|
accessToken(email: "access-token@user-resolver.com", password: "password") { |
|
|
|
|
|
|
|
jwt |
|
|
|
|
|
|
|
jwtExpiry |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
const meQuery = gql` |
|
|
|
|
|
|
|
query { |
|
|
|
|
|
|
|
me { |
|
|
|
|
|
|
|
email |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
const contextWithAuthHeader = (header: string): Context => ({ |
|
|
|
const contextWithAuthHeader = (header: string): Context => ({ |
|
|
|
req: { |
|
|
|
req: { |
|
|
|
headers: { |
|
|
|
headers: { |
|
|
|