-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New test cases and various bugs fixed"
- Loading branch information
JohannC
committed
Nov 20, 2019
1 parent
aa69edf
commit 4ffeebf
Showing
3 changed files
with
221 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const AppTester = require('../utils/AppTester'); | ||
const jwt = require('jsonwebtoken'); | ||
const config = require('../../lib/config') | ||
|
||
let appTester; | ||
let request; | ||
let token | ||
let user = { | ||
username: "username", | ||
email: "test@test.com", | ||
password: "password", | ||
firstName: "firstname", | ||
lastName: "lastname", | ||
age: 23, | ||
gender: "Mrs", | ||
receiveNewsletter: true | ||
}; | ||
|
||
let user2 = { | ||
username: "username2", | ||
email: "test2@test.com", | ||
password: "password", | ||
firstName: "firstname", | ||
lastName: "lastname", | ||
age: 23, | ||
gender: "Mrs", | ||
receiveNewsletter: true | ||
}; | ||
|
||
beforeAll((done) => { | ||
appTester = new AppTester({ | ||
dbConfig: { | ||
userDB: "ConfirmEmailTest" | ||
}, | ||
onReady: async () => { | ||
try{ | ||
request = appTester.getRequestSender(); | ||
await appTester.register(user); | ||
await appTester.register(user2); | ||
res = await appTester.login(user.email, user.password); | ||
token = res.data.login.token; | ||
done(); | ||
} catch (err) { | ||
done(err); | ||
} | ||
} | ||
}); | ||
}, 40000); | ||
|
||
test("Confirm email", async (done) => { | ||
const recoveryEmailQuery = { | ||
query: `query{ | ||
sendVerificationEmail{ | ||
notifications{ | ||
type | ||
message | ||
} | ||
} | ||
}` | ||
} | ||
let res = await request.getGraphQL(recoveryEmailQuery, token); | ||
expect(res.data.sendVerificationEmail.notifications[0].message.includes("You will receive a confirmation link at your email address in a few minutes")).toBeTruthy(); | ||
|
||
|
||
|
||
const UserModel = require('../../lib/model/UserModel'); | ||
const userRetrieved = await UserModel.getUser({username: user.username}, {verified: true}); | ||
res = await request.get("/user/email/confirmation?token="+userRetrieved.verificationToken); | ||
expect(res.statusCode).toBe(200); | ||
expect(res.text.includes("You are now verified")).toBeTruthy(); | ||
done(); | ||
}); | ||
|
||
test("wrong verify token", async (done) => { | ||
res = await request.get("/user/email/confirmation?token=" + "WRONGTOKEN"); | ||
expect(res.statusCode).toBe(200); | ||
expect(res.text.includes("This link is not valid!")).toBeTruthy(); | ||
done(); | ||
}); | ||
|
||
afterAll(async (done) => { | ||
await appTester.close(done); | ||
}, 40000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters