|
1 | 1 | import { test, expect } from '@playwright/test' |
2 | 2 | import { testUser, riskResponse, compareUnordered, compareOrdered } from './helpers' |
3 | 3 |
|
| 4 | +const baseUrl = 'http://localhost:8000' |
| 5 | + |
4 | 6 | test.describe.configure({ mode: 'serial' }) |
5 | 7 |
|
6 | 8 | test.describe('api', () => { |
@@ -32,7 +34,7 @@ test.describe('api', () => { |
32 | 34 | tuhatData: {}, |
33 | 35 | } |
34 | 36 |
|
35 | | - const response = await fetch('http://localhost:8000/api/entries/1/dryrun', { |
| 37 | + const response = await fetch(`${baseUrl}/api/entries/1/dryrun`, { |
36 | 38 | method: 'POST', |
37 | 39 | headers: { 'Content-Type': 'application/json' }, |
38 | 40 | body: JSON.stringify(payload), |
@@ -85,7 +87,7 @@ test.describe('api', () => { |
85 | 87 | tuhatData: {}, |
86 | 88 | } |
87 | 89 |
|
88 | | - const response = await fetch('http://localhost:8000/api/entries/1/dryrun', { |
| 90 | + const response = await fetch(`${baseUrl}/api/entries/1/dryrun`, { |
89 | 91 | method: 'POST', |
90 | 92 | headers: { 'Content-Type': 'application/json' }, |
91 | 93 | body: JSON.stringify(payload), |
@@ -148,4 +150,151 @@ test.describe('api', () => { |
148 | 150 | expect(data.country[0].code).toStrictEqual('AF') |
149 | 151 | compareOrdered(data.multilateralCountries, expectedCountries) |
150 | 152 | }) |
| 153 | + |
| 154 | + test('editing an entry', async () => { |
| 155 | + const initialPayload = { |
| 156 | + data: { |
| 157 | + '1': 'Testi Kayttaja', |
| 158 | + '2': testUser, |
| 159 | + '3': 'Initial Project', |
| 160 | + '4': 'bilateral', |
| 161 | + '6': 'university', |
| 162 | + '8': 'Afghanistan', |
| 163 | + '9': 'partner', |
| 164 | + '10': 'agreementNotDone', |
| 165 | + '11': ['education'], |
| 166 | + '12': 'mediumDuration', |
| 167 | + '13': 'noExternalFunding', |
| 168 | + '16': 'mediumBudget', |
| 169 | + '17': 'noTransferPersonalData', |
| 170 | + '20': 'Kardan University', |
| 171 | + '23': 'noTransferMilitaryKnowledge', |
| 172 | + '24': 'noSuccessfulCollaboration', |
| 173 | + '25': 'likelyNoEthicalIssues', |
| 174 | + faculty: 'H40', |
| 175 | + unit: 'H528', |
| 176 | + tuhatProjectExists: 'tuhatOptionNegative', |
| 177 | + }, |
| 178 | + sessionToken: 'e1e841e1-1368-4deb-b9f9-227ab1261e64', |
| 179 | + tuhatData: {}, |
| 180 | + } |
| 181 | + |
| 182 | + const createResponse = await fetch(`${baseUrl}/api/entries/1`, { |
| 183 | + method: 'POST', |
| 184 | + headers: { 'Content-Type': 'application/json' }, |
| 185 | + body: JSON.stringify(initialPayload), |
| 186 | + }) |
| 187 | + |
| 188 | + expect(createResponse.status).toBe(201) |
| 189 | + const createdEntry = await createResponse.json() |
| 190 | + |
| 191 | + let updatedPayload = { |
| 192 | + data: { |
| 193 | + '1': 'Testi Kayttaja', |
| 194 | + '2': testUser, |
| 195 | + '3': 'Updated Project Name', |
| 196 | + '4': 'bilateral', |
| 197 | + '6': 'university', |
| 198 | + '8': 'Sweden', |
| 199 | + '9': 'coordinator', |
| 200 | + '10': 'agreementDone', |
| 201 | + '11': ['education', 'research'], |
| 202 | + '12': 'longDuration', |
| 203 | + '13': 'externalFunding', |
| 204 | + '16': 'largeBudget', |
| 205 | + '17': 'noTransferPersonalData', |
| 206 | + '20': 'Ahlobait University', |
| 207 | + '23': 'noTransferMilitaryKnowledge', |
| 208 | + '24': 'successfulCollaboration', |
| 209 | + '25': 'likelyNoEthicalIssues', |
| 210 | + faculty: 'H40', |
| 211 | + unit: 'H528', |
| 212 | + tuhatProjectExists: 'tuhatOptionNegative', |
| 213 | + }, |
| 214 | + tuhatData: {}, |
| 215 | + } |
| 216 | + |
| 217 | + let updateResponse = await fetch(`${baseUrl}/api/entries/${createdEntry.id}`, { |
| 218 | + method: 'PUT', |
| 219 | + headers: { 'Content-Type': 'application/json' }, |
| 220 | + body: JSON.stringify(updatedPayload), |
| 221 | + }) |
| 222 | + |
| 223 | + expect(updateResponse.status).toBe(200) |
| 224 | + |
| 225 | + let updatedEntry = await updateResponse.json() |
| 226 | + |
| 227 | + let expectedRisks = riskResponse([ |
| 228 | + { id: 'country', level: 1 }, |
| 229 | + { id: 'dualUseEU', level: 1 }, |
| 230 | + { id: 'economic', level: 3 }, |
| 231 | + { id: 'economicScope', level: 3 }, |
| 232 | + { id: 'ethical', level: 1 }, |
| 233 | + { id: 'total', level: 2 }, |
| 234 | + { id: 'university', level: 1 }, |
| 235 | + ]) |
| 236 | + |
| 237 | + compareUnordered(updatedEntry.data.risks, expectedRisks) |
| 238 | + |
| 239 | + expect(updatedEntry.data.country[0].code).toBe('SE') |
| 240 | + |
| 241 | + expect(updatedEntry.data.updatedData).toBeDefined() |
| 242 | + expect(updatedEntry.data.updatedData.length).toBe(1) |
| 243 | + expect(updatedEntry.data.updatedData[0].country[0].code).toBe('AF') |
| 244 | + |
| 245 | + updatedPayload = { |
| 246 | + data: { |
| 247 | + '1': 'Testi Kayttaja', |
| 248 | + '2': testUser, |
| 249 | + '3': 'Updated Project Name', |
| 250 | + '4': 'bilateral', |
| 251 | + '6': 'university', |
| 252 | + '8': 'Denmark', |
| 253 | + '9': 'coordinator', |
| 254 | + '10': 'agreementDone', |
| 255 | + '11': ['education', 'research'], |
| 256 | + '12': 'shortDuration', |
| 257 | + '13': 'noExternalFunding', |
| 258 | + '16': 'smallBudget', |
| 259 | + '17': 'noTransferPersonalData', |
| 260 | + '20': 'Ahlobait University', |
| 261 | + '23': 'noTransferMilitaryKnowledge', |
| 262 | + '24': 'successfulCollaboration', |
| 263 | + '25': 'likelyNoEthicalIssues', |
| 264 | + faculty: 'H40', |
| 265 | + unit: 'H528', |
| 266 | + tuhatProjectExists: 'tuhatOptionNegative', |
| 267 | + }, |
| 268 | + tuhatData: {}, |
| 269 | + } |
| 270 | + |
| 271 | + updateResponse = await fetch(`${baseUrl}/api/entries/${createdEntry.id}`, { |
| 272 | + method: 'PUT', |
| 273 | + headers: { 'Content-Type': 'application/json' }, |
| 274 | + body: JSON.stringify(updatedPayload), |
| 275 | + }) |
| 276 | + |
| 277 | + expect(updateResponse.status).toBe(200) |
| 278 | + |
| 279 | + updatedEntry = await updateResponse.json() |
| 280 | + |
| 281 | + expectedRisks = riskResponse([ |
| 282 | + { id: 'country', level: 1 }, |
| 283 | + { id: 'dualUseEU', level: 1 }, |
| 284 | + { id: 'economic', level: 1 }, |
| 285 | + { id: 'economicScope', level: 1 }, |
| 286 | + { id: 'ethical', level: 1 }, |
| 287 | + { id: 'total', level: 1 }, |
| 288 | + { id: 'university', level: 1 }, |
| 289 | + ]) |
| 290 | + |
| 291 | + compareUnordered(updatedEntry.data.risks, expectedRisks) |
| 292 | + |
| 293 | + expect(updatedEntry.data.country[0].code).toBe('DK') |
| 294 | + |
| 295 | + expect(updatedEntry.data.updatedData).toBeDefined() |
| 296 | + expect(updatedEntry.data.updatedData.length).toBe(2) |
| 297 | + expect(updatedEntry.data.updatedData[0].country[0].code).toBe('AF') |
| 298 | + expect(updatedEntry.data.updatedData[1].country[0].code).toBe('SE') |
| 299 | + }) |
151 | 300 | }) |
0 commit comments