@@ -3,14 +3,9 @@ import {
3
3
VERIFICATION_STRING ,
4
4
} from "../../../src/constants/responses" ;
5
5
import config from "../../../config/config" ;
6
+ import { UNIQUE_TOKEN , discordUserData , env , mockDateNow } from "../../fixtures/fixture" ;
7
+
6
8
7
- const mockDateNow = 1626512345678 ;
8
- const UNIQUE_TOKEN = "UNIQUE_TOKEN" ;
9
- const env = {
10
- BOT_PUBLIC_KEY : "BOT_PUBLIC_KEY" ,
11
- DISCORD_GUILD_ID : "DISCORD_GUILD_ID" ,
12
- DISCORD_TOKEN : "SIGNED_JWT" ,
13
- } ;
14
9
15
10
describe ( "verifyCommand" , ( ) => {
16
11
beforeEach ( ( ) => {
@@ -26,22 +21,11 @@ describe("verifyCommand", () => {
26
21
} ) ;
27
22
28
23
test ( "should return JSON response when response is ok" , async ( ) => {
29
- const data = {
30
- type : "discord" ,
31
- token : UNIQUE_TOKEN ,
32
- attributes : {
33
- discordId : 1 ,
34
- userAvatar : "https://cdn.discordapp.com/avatars/1/userAvatarHash.jpg" ,
35
- userName : "userName" ,
36
- discriminator : "discriminator" ,
37
- expiry : mockDateNow + 1000 * 60 * 2 ,
38
- } ,
39
- } ;
40
24
41
25
jest . spyOn ( global , "fetch" ) . mockResolvedValueOnce ( {
42
26
ok : true ,
43
27
status : 200 ,
44
- json : jest . fn ( ) . mockResolvedValueOnce ( data ) ,
28
+ json : jest . fn ( ) . mockResolvedValueOnce ( discordUserData ) ,
45
29
} as unknown as Response ) ;
46
30
47
31
const { verifyCommand } = await import (
@@ -64,7 +48,7 @@ describe("verifyCommand", () => {
64
48
"Content-Type" : "application/json" ,
65
49
Authorization : `Bearer ${ env . DISCORD_TOKEN } ` ,
66
50
} ,
67
- body : JSON . stringify ( data ) ,
51
+ body : JSON . stringify ( discordUserData ) ,
68
52
}
69
53
) ;
70
54
const resultText = await result . text ( ) ;
@@ -79,22 +63,11 @@ describe("verifyCommand", () => {
79
63
} ) ;
80
64
81
65
test ( "should return INTERNAL_SERVER_ERROR when response is not ok" , async ( ) => {
82
- const data = {
83
- type : "discord" ,
84
- token : UNIQUE_TOKEN ,
85
- attributes : {
86
- discordId : 1 ,
87
- userAvatar : "https://cdn.discordapp.com/avatars/1/userAvatarHash.jpg" ,
88
- userName : "userName" ,
89
- discriminator : "discriminator" ,
90
- expiry : mockDateNow + 1000 * 60 * 2 ,
91
- } ,
92
- } ;
93
66
94
67
jest . spyOn ( global , "fetch" ) . mockResolvedValueOnce ( {
95
68
ok : true ,
96
69
status : 400 , // ERROR STATUS
97
- json : jest . fn ( ) . mockResolvedValueOnce ( data ) ,
70
+ json : jest . fn ( ) . mockResolvedValueOnce ( discordUserData ) ,
98
71
} as unknown as Response ) ;
99
72
100
73
const { verifyCommand } = await import (
@@ -116,7 +89,7 @@ describe("verifyCommand", () => {
116
89
"Content-Type" : "application/json" ,
117
90
Authorization : `Bearer ${ env . DISCORD_TOKEN } ` ,
118
91
} ,
119
- body : JSON . stringify ( data ) ,
92
+ body : JSON . stringify ( discordUserData ) ,
120
93
}
121
94
) ;
122
95
const resultText = await result . text ( ) ;
0 commit comments