method.unit.test.js 1.85 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
const methods = require('../functions/methods')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
2
3

describe("DB methohds test", () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
4

Rosanny Sihombing's avatar
Rosanny Sihombing committed
5
6
7
    it("returns a user from DB by email", async() => {
        const user = await methods.getUserByEmail('litehon958@whipjoy.com')
        expect(user).not.toBeNull()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
8
    })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    it("returns a null user", async() => {
        const user = await methods.getUserByEmail('jondoe@nowhere.com') // a non-exist user
        expect(user).toBeNull()
    })

    it("returns a user's email", async() => {
        const email = await methods.getUserEmailById(1)
        expect(email).not.toBeNull()
    })
    it("returns null instead of a user's email", async() => {
        const email = await methods.getUserEmailById(1005) // no user has this ID
        expect(email).toBeNull()
    })

    it("returns null from DB by token", async() => {
        const user = await methods.getUserByToken('12345678') // unvalid token
        expect(user).toBeNull() // for valid token = expect(user).not.toBeNull()
    })

    it("returns a user's verification token, if any", async() => {
        const token = await methods.getVerificationTokenByUserId(1)
        expect(token).toBeNull()
    })

    it("returns a user's ID, if any", async() => {
        const token = await methods.getUserIdByVerificationToken('12345678') // unvalid token
        expect(token).toBeNull() // for valid token = expect(user).not.toBeNull()
    })

    it("returns a user's GitLab_ID, if any", async() => {
        const id = await methods.getGitlabId(1)
        expect(id).not.toBeNull()
    })

    it("checks user email", async() => {
        const user = await methods.checkUserEmail('litehon958@whipjoy.com')
        expect(user).not.toBeNull()
    })
    it("checks user email and return null", async() => {
        const user = await methods.checkUserEmail('jondoe@nowhere.com') // a non-exist user
        expect(user).toBeNull()
    })

Rosanny Sihombing's avatar
Rosanny Sihombing committed
52
})