@@ -11,10 +11,28 @@ import { createCandidacyHelper } from "../../../../test/helpers/entities/create-
11
11
import { injectGraphql } from "../../../../test/helpers/graphql-helper" ;
12
12
import { clearDatabase } from "../../../../test/jestClearDatabaseBeforeEachTestFile" ;
13
13
import { createCandidacyContestationCaducite } from "./createCandidacyContestationCaducite" ;
14
+ import { randomUUID } from "crypto" ;
14
15
15
16
const VALID_CONTESTATION_REASON = "Valid contestation reason" ;
16
17
const FUTURE_DATE = addDays ( new Date ( ) , 30 ) ;
17
18
const PAST_DATE = subDays ( new Date ( ) , 1 ) ;
19
+ const CONTEXT = {
20
+ auth : {
21
+ userInfo : {
22
+ sub : randomUUID ( ) ,
23
+ email : "test@test.com" ,
24
+ email_verified : true ,
25
+ preferred_username : "test" ,
26
+ realm_access : { roles : [ "candidate" as KeyCloakUserRole ] } ,
27
+ } ,
28
+ hasRole : ( _role : string ) => true ,
29
+ } ,
30
+ app : {
31
+ keycloak : {
32
+ hasRole : ( _role : string ) => true ,
33
+ } ,
34
+ } ,
35
+ } ;
18
36
19
37
const createContestationMutation = async ( {
20
38
keycloakId,
@@ -55,9 +73,12 @@ describe("createCandidacyContestationCaducite", () => {
55
73
const candidacy = await createCandidacyHelper ( ) ;
56
74
57
75
const createContestationPromise = createCandidacyContestationCaducite ( {
58
- candidacyId : candidacy . id ,
59
- contestationReason : "" ,
60
- readyForJuryEstimatedAt : FUTURE_DATE ,
76
+ input : {
77
+ candidacyId : candidacy . id ,
78
+ contestationReason : "" ,
79
+ readyForJuryEstimatedAt : FUTURE_DATE ,
80
+ } ,
81
+ context : CONTEXT ,
61
82
} ) ;
62
83
63
84
await expect ( createContestationPromise ) . rejects . toThrow (
@@ -69,9 +90,12 @@ describe("createCandidacyContestationCaducite", () => {
69
90
const candidacy = await createCandidacyHelper ( ) ;
70
91
71
92
const createContestationPromise = createCandidacyContestationCaducite ( {
72
- candidacyId : candidacy . id ,
73
- contestationReason : VALID_CONTESTATION_REASON ,
74
- readyForJuryEstimatedAt : PAST_DATE ,
93
+ input : {
94
+ candidacyId : candidacy . id ,
95
+ contestationReason : VALID_CONTESTATION_REASON ,
96
+ readyForJuryEstimatedAt : PAST_DATE ,
97
+ } ,
98
+ context : CONTEXT ,
75
99
} ) ;
76
100
77
101
await expect ( createContestationPromise ) . rejects . toThrow (
@@ -83,9 +107,12 @@ describe("createCandidacyContestationCaducite", () => {
83
107
describe ( "Candidacy validation" , ( ) => {
84
108
test ( "should fail when candidacy does not exist" , async ( ) => {
85
109
const createContestationPromise = createCandidacyContestationCaducite ( {
86
- candidacyId : faker . string . uuid ( ) ,
87
- contestationReason : VALID_CONTESTATION_REASON ,
88
- readyForJuryEstimatedAt : FUTURE_DATE ,
110
+ input : {
111
+ candidacyId : faker . string . uuid ( ) ,
112
+ contestationReason : VALID_CONTESTATION_REASON ,
113
+ readyForJuryEstimatedAt : FUTURE_DATE ,
114
+ } ,
115
+ context : CONTEXT ,
89
116
} ) ;
90
117
91
118
await expect ( createContestationPromise ) . rejects . toThrow (
@@ -106,9 +133,12 @@ describe("createCandidacyContestationCaducite", () => {
106
133
} ) ;
107
134
108
135
const createContestationPromise = createCandidacyContestationCaducite ( {
109
- candidacyId : candidacy . id ,
110
- contestationReason : VALID_CONTESTATION_REASON ,
111
- readyForJuryEstimatedAt : FUTURE_DATE ,
136
+ input : {
137
+ candidacyId : candidacy . id ,
138
+ contestationReason : VALID_CONTESTATION_REASON ,
139
+ readyForJuryEstimatedAt : FUTURE_DATE ,
140
+ } ,
141
+ context : CONTEXT ,
112
142
} ) ;
113
143
114
144
await expect ( createContestationPromise ) . rejects . toThrow (
@@ -129,9 +159,12 @@ describe("createCandidacyContestationCaducite", () => {
129
159
} ) ;
130
160
131
161
const createContestationPromise = createCandidacyContestationCaducite ( {
132
- candidacyId : candidacy . id ,
133
- contestationReason : VALID_CONTESTATION_REASON ,
134
- readyForJuryEstimatedAt : FUTURE_DATE ,
162
+ input : {
163
+ candidacyId : candidacy . id ,
164
+ contestationReason : VALID_CONTESTATION_REASON ,
165
+ readyForJuryEstimatedAt : FUTURE_DATE ,
166
+ } ,
167
+ context : CONTEXT ,
135
168
} ) ;
136
169
137
170
await expect ( createContestationPromise ) . rejects . toThrow (
@@ -145,9 +178,12 @@ describe("createCandidacyContestationCaducite", () => {
145
178
const candidacy = await createCandidacyHelper ( ) ;
146
179
147
180
const result = await createCandidacyContestationCaducite ( {
148
- candidacyId : candidacy . id ,
149
- contestationReason : VALID_CONTESTATION_REASON ,
150
- readyForJuryEstimatedAt : FUTURE_DATE ,
181
+ input : {
182
+ candidacyId : candidacy . id ,
183
+ contestationReason : VALID_CONTESTATION_REASON ,
184
+ readyForJuryEstimatedAt : FUTURE_DATE ,
185
+ } ,
186
+ context : CONTEXT ,
151
187
} ) ;
152
188
153
189
expect ( result ) . toMatchObject ( {
@@ -176,9 +212,12 @@ describe("createCandidacyContestationCaducite", () => {
176
212
} ) ;
177
213
178
214
const result = await createCandidacyContestationCaducite ( {
179
- candidacyId : candidacy . id ,
180
- contestationReason : VALID_CONTESTATION_REASON ,
181
- readyForJuryEstimatedAt : FUTURE_DATE ,
215
+ input : {
216
+ candidacyId : candidacy . id ,
217
+ contestationReason : VALID_CONTESTATION_REASON ,
218
+ readyForJuryEstimatedAt : FUTURE_DATE ,
219
+ } ,
220
+ context : CONTEXT ,
182
221
} ) ;
183
222
184
223
expect ( result ) . toMatchObject ( {
0 commit comments