Skip to content

Commit e59f3b0

Browse files
committed
feat: Update API endpoints in user and cloud credentials tests to include '/api' prefix for consistency
1 parent bfbafca commit e59f3b0

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

services/backend/src/routes/users/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const userTeamsResponseSchema = z.object({
4242
created_at: z.date().describe('Team creation date'),
4343
updated_at: z.date().describe('Team last update date'),
4444
role: z.enum(['team_admin', 'team_user']).describe('User role in the team'),
45-
is_admin: z.boolean().describe('Whether the user is an admin of this team')
45+
is_owner: z.boolean().describe('Whether the user is the owner of this team')
4646
})).describe('Array of user teams')
4747
});
4848

@@ -633,7 +633,7 @@ export default async function usersRoute(fastify: FastifyInstance) {
633633
return {
634634
...team,
635635
role: membership?.role || 'team_user',
636-
is_admin: membership?.role === 'team_admin'
636+
is_owner: team.owner_id === request.user!.id
637637
};
638638
})
639639
);

services/backend/tests/e2e/15-cloud-credentials.e2e.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('Cloud Credentials E2E Tests', () => {
126126
const context = getTestContext();
127127

128128
const response = await request(server.server)
129-
.get(`/teams/${context.teamAdminTeamId}/cloud-providers`)
129+
.get(`/api/teams/${context.teamAdminTeamId}/cloud-providers`)
130130
.set('Cookie', context.teamAdminCredentialsCookie!);
131131

132132
expect(response.status).toBe(200);
@@ -168,7 +168,7 @@ describe('Cloud Credentials E2E Tests', () => {
168168
};
169169

170170
const response = await request(server.server)
171-
.post(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
171+
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
172172
.set('Cookie', context.teamAdminCredentialsCookie!)
173173
.send(credentialData);
174174

@@ -221,7 +221,7 @@ describe('Cloud Credentials E2E Tests', () => {
221221
};
222222

223223
const response = await request(server.server)
224-
.post(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
224+
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
225225
.set('Cookie', context.teamAdminCredentialsCookie!)
226226
.send(credentialData);
227227

@@ -251,7 +251,7 @@ describe('Cloud Credentials E2E Tests', () => {
251251
};
252252

253253
const response = await request(server.server)
254-
.put(`/teams/${context.teamAdminTeamId}/cloud-credentials/${context.editTestCredentialId}`)
254+
.put(`/api/teams/${context.teamAdminTeamId}/cloud-credentials/${context.editTestCredentialId}`)
255255
.set('Cookie', context.teamAdminCredentialsCookie!)
256256
.send(updateData);
257257

@@ -277,7 +277,7 @@ describe('Cloud Credentials E2E Tests', () => {
277277
const context = getTestContext();
278278

279279
const response = await request(server.server)
280-
.delete(`/teams/${context.teamAdminTeamId}/cloud-credentials/${context.editTestCredentialId}`)
280+
.delete(`/api/teams/${context.teamAdminTeamId}/cloud-credentials/${context.editTestCredentialId}`)
281281
.set('Cookie', context.teamAdminCredentialsCookie!);
282282

283283
expect(response.status).toBe(200);
@@ -286,7 +286,7 @@ describe('Cloud Credentials E2E Tests', () => {
286286

287287
// Verify credential is deleted by trying to get it
288288
const getResponse = await request(server.server)
289-
.get(`/teams/${context.teamAdminTeamId}/cloud-credentials/${context.editTestCredentialId}`)
289+
.get(`/api/teams/${context.teamAdminTeamId}/cloud-credentials/${context.editTestCredentialId}`)
290290
.set('Cookie', context.teamAdminCredentialsCookie!);
291291

292292
expect(getResponse.status).toBe(404);
@@ -307,7 +307,7 @@ describe('Cloud Credentials E2E Tests', () => {
307307
};
308308

309309
const response1 = await request(server.server)
310-
.post(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
310+
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
311311
.set('Cookie', context.teamAdminCredentialsCookie!)
312312
.send(credential1Data);
313313

@@ -326,7 +326,7 @@ describe('Cloud Credentials E2E Tests', () => {
326326
};
327327

328328
const response2 = await request(server.server)
329-
.post(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
329+
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
330330
.set('Cookie', context.teamAdminCredentialsCookie!)
331331
.send(credential2Data);
332332

@@ -344,7 +344,7 @@ describe('Cloud Credentials E2E Tests', () => {
344344
const context = getTestContext();
345345

346346
const response = await request(server.server)
347-
.get(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
347+
.get(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
348348
.set('Cookie', context.globalAdminCredentialsCookie!);
349349

350350
expect(response.status).toBe(200);
@@ -387,7 +387,7 @@ describe('Cloud Credentials E2E Tests', () => {
387387
const context = getTestContext();
388388

389389
const response = await request(server.server)
390-
.get('/teams/non-existent-team-id/cloud-credentials')
390+
.get('/api/teams/non-existent-team-id/cloud-credentials')
391391
.set('Cookie', context.globalAdminCredentialsCookie!);
392392

393393
// Global admin should not be able to access non-existent team
@@ -400,7 +400,7 @@ describe('Cloud Credentials E2E Tests', () => {
400400
const context = getTestContext();
401401

402402
const response = await request(server.server)
403-
.get(`/teams/${context.teamAdminTeamId}/cloud-credentials/${context.prodCredentialId}`)
403+
.get(`/api/teams/${context.teamAdminTeamId}/cloud-credentials/${context.prodCredentialId}`)
404404
.set('Cookie', context.globalAdminCredentialsCookie!);
405405

406406
expect(response.status).toBe(200);
@@ -426,7 +426,7 @@ describe('Cloud Credentials E2E Tests', () => {
426426

427427
// Test as global admin viewing other team's credentials
428428
const globalAdminResponse = await request(server.server)
429-
.get(`/teams/${context.teamAdminTeamId}/cloud-credentials/${context.prodCredentialId}`)
429+
.get(`/api/teams/${context.teamAdminTeamId}/cloud-credentials/${context.prodCredentialId}`)
430430
.set('Cookie', context.globalAdminCredentialsCookie!);
431431

432432
expect(globalAdminResponse.status).toBe(200);
@@ -444,7 +444,7 @@ describe('Cloud Credentials E2E Tests', () => {
444444

445445
// Test as team admin viewing own team's credentials
446446
const teamAdminResponse = await request(server.server)
447-
.get(`/teams/${context.teamAdminTeamId}/cloud-credentials/${context.prodCredentialId}`)
447+
.get(`/api/teams/${context.teamAdminTeamId}/cloud-credentials/${context.prodCredentialId}`)
448448
.set('Cookie', context.teamAdminCredentialsCookie!);
449449

450450
expect(teamAdminResponse.status).toBe(200);
@@ -462,7 +462,7 @@ describe('Cloud Credentials E2E Tests', () => {
462462

463463
// Test invalid provider ID
464464
const invalidProviderResponse = await request(server.server)
465-
.post(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
465+
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
466466
.set('Cookie', context.teamAdminCredentialsCookie!)
467467
.send({
468468
providerId: 'invalid-provider',
@@ -476,7 +476,7 @@ describe('Cloud Credentials E2E Tests', () => {
476476

477477
// Test missing required fields
478478
const missingFieldsResponse = await request(server.server)
479-
.post(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
479+
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
480480
.set('Cookie', context.teamAdminCredentialsCookie!)
481481
.send({
482482
providerId: 'aws',
@@ -493,7 +493,7 @@ describe('Cloud Credentials E2E Tests', () => {
493493

494494
// Test duplicate credential name
495495
const duplicateNameResponse = await request(server.server)
496-
.post(`/teams/${context.teamAdminTeamId}/cloud-credentials`)
496+
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
497497
.set('Cookie', context.teamAdminCredentialsCookie!)
498498
.send({
499499
providerId: 'aws',
@@ -514,15 +514,15 @@ describe('Cloud Credentials E2E Tests', () => {
514514

515515
// Test without authentication
516516
const noAuthResponse = await request(server.server)
517-
.get(`/teams/${context.regularUserTeamId}/cloud-credentials`);
517+
.get(`/api/teams/${context.regularUserTeamId}/cloud-credentials`);
518518

519519
expect(noAuthResponse.status).toBe(401);
520520
expect(noAuthResponse.body.success).toBe(false);
521521
expect(noAuthResponse.body.error).toBeDefined();
522522

523523
// Test accessing non-existent team
524524
const invalidTeamResponse = await request(server.server)
525-
.get('/teams/non-existent-team-id/cloud-credentials')
525+
.get('/api/teams/non-existent-team-id/cloud-credentials')
526526
.set('Cookie', context.regularUserCredentialsCookie!);
527527

528528
expect(invalidTeamResponse.status).toBe(403);
@@ -531,7 +531,7 @@ describe('Cloud Credentials E2E Tests', () => {
531531

532532
// Test accessing non-existent credential
533533
const invalidCredentialResponse = await request(server.server)
534-
.get(`/teams/${context.regularUserTeamId}/cloud-credentials/non-existent-credential-id`)
534+
.get(`/api/teams/${context.regularUserTeamId}/cloud-credentials/non-existent-credential-id`)
535535
.set('Cookie', context.regularUserCredentialsCookie!);
536536

537537
expect(invalidCredentialResponse.status).toBe(404);

services/backend/tests/e2e/16-cloud-credentials-cross-user-permissions.e2e.test.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
141141
};
142142

143143
const response = await request(server.server)
144-
.post(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
144+
.post(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
145145
.set('Cookie', context.testCredentialsUser1Cookie!)
146146
.send(credentialData);
147147

@@ -156,7 +156,9 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
156156
expect(credential.providerId).toBe('aws');
157157
expect(credential.name).toBe(credentialData.name);
158158
expect(credential.comment).toBe(credentialData.comment);
159-
expect(credential.createdBy).toBe(context.testCredentialsUser1Id);
159+
// Handle both possible response formats for createdBy
160+
const createdById = typeof credential.createdBy === 'object' ? credential.createdBy.id : credential.createdBy;
161+
expect(createdById).toBe(context.testCredentialsUser1Id);
160162

161163
// Verify provider information
162164
expect(credential.provider.id).toBe('aws');
@@ -185,7 +187,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
185187

186188
// User 2 attempts to list User 1's team credentials
187189
const response = await request(server.server)
188-
.get(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
190+
.get(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
189191
.set('Cookie', context.testCredentialsUser2Cookie!);
190192

191193
// Should be forbidden - User 2 is not a member of User 1's team
@@ -199,7 +201,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
199201

200202
// User 2 attempts to view User 1's specific credential
201203
const response = await request(server.server)
202-
.get(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
204+
.get(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
203205
.set('Cookie', context.testCredentialsUser2Cookie!);
204206

205207
// Should be forbidden - User 2 is not a member of User 1's team
@@ -221,7 +223,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
221223

222224
// User 2 attempts to update User 1's credential
223225
const response = await request(server.server)
224-
.put(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
226+
.put(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
225227
.set('Cookie', context.testCredentialsUser2Cookie!)
226228
.send(updateData);
227229

@@ -236,7 +238,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
236238

237239
// User 2 attempts to delete User 1's credential
238240
const response = await request(server.server)
239-
.delete(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
241+
.delete(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
240242
.set('Cookie', context.testCredentialsUser2Cookie!);
241243

242244
// Should be forbidden - User 2 is not a member of User 1's team
@@ -250,7 +252,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
250252

251253
// User 1 verifies their credential still exists and is unchanged
252254
const response = await request(server.server)
253-
.get(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
255+
.get(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials/${context.testCredentialsUser1CredentialId}`)
254256
.set('Cookie', context.testCredentialsUser1Cookie!);
255257

256258
expect(response.status).toBe(200);
@@ -260,7 +262,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
260262
const credential = response.body.data;
261263
expect(credential.name).toBe('User1 Test Credentials'); // Original name unchanged
262264
expect(credential.comment).toBe('Test credentials for cross-user permission testing'); // Original comment unchanged
263-
expect(credential.createdBy).toBe(context.testCredentialsUser1Id);
265+
expect(credential.createdBy.id).toBe(context.testCredentialsUser1Id);
264266
expect(credential.teamId).toBe(context.testCredentialsUser1TeamId);
265267

266268
// Verify fields are still intact
@@ -283,7 +285,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
283285
};
284286

285287
const createResponse = await request(server.server)
286-
.post(`/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
288+
.post(`/api/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
287289
.set('Cookie', context.testCredentialsUser2Cookie!)
288290
.send(credentialData);
289291

@@ -293,14 +295,16 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
293295

294296
const credential = createResponse.body.data;
295297
expect(credential.teamId).toBe(context.testCredentialsUser2TeamId);
296-
expect(credential.createdBy).toBe(context.testCredentialsUser2Id);
298+
// Handle both possible response formats for createdBy
299+
const createdById = typeof credential.createdBy === 'object' ? credential.createdBy.id : credential.createdBy;
300+
expect(createdById).toBe(context.testCredentialsUser2Id);
297301
expect(credential.name).toBe(credentialData.name);
298302

299303
const user2CredentialId = credential.id;
300304

301305
// User 2 can list their own team's credentials
302306
const listResponse = await request(server.server)
303-
.get(`/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
307+
.get(`/api/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
304308
.set('Cookie', context.testCredentialsUser2Cookie!);
305309

306310
expect(listResponse.status).toBe(200);
@@ -310,7 +314,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
310314

311315
// User 2 can view their own credential
312316
const viewResponse = await request(server.server)
313-
.get(`/teams/${context.testCredentialsUser2TeamId}/cloud-credentials/${user2CredentialId}`)
317+
.get(`/api/teams/${context.testCredentialsUser2TeamId}/cloud-credentials/${user2CredentialId}`)
314318
.set('Cookie', context.testCredentialsUser2Cookie!);
315319

316320
expect(viewResponse.status).toBe(200);
@@ -324,7 +328,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
324328
};
325329

326330
const updateResponse = await request(server.server)
327-
.put(`/teams/${context.testCredentialsUser2TeamId}/cloud-credentials/${user2CredentialId}`)
331+
.put(`/api/teams/${context.testCredentialsUser2TeamId}/cloud-credentials/${user2CredentialId}`)
328332
.set('Cookie', context.testCredentialsUser2Cookie!)
329333
.send(updateData);
330334

@@ -335,7 +339,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
335339

336340
// User 2 can delete their own credential
337341
const deleteResponse = await request(server.server)
338-
.delete(`/teams/${context.testCredentialsUser2TeamId}/cloud-credentials/${user2CredentialId}`)
342+
.delete(`/api/teams/${context.testCredentialsUser2TeamId}/cloud-credentials/${user2CredentialId}`)
339343
.set('Cookie', context.testCredentialsUser2Cookie!);
340344

341345
expect(deleteResponse.status).toBe(200);
@@ -348,23 +352,23 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
348352

349353
// User 1 should not be able to access User 2's team
350354
const user1AccessUser2TeamResponse = await request(server.server)
351-
.get(`/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
355+
.get(`/api/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
352356
.set('Cookie', context.testCredentialsUser1Cookie!);
353357

354358
expect(user1AccessUser2TeamResponse.status).toBe(403);
355359
expect(user1AccessUser2TeamResponse.body.success).toBe(false);
356360

357361
// User 2 should not be able to access User 1's team
358362
const user2AccessUser1TeamResponse = await request(server.server)
359-
.get(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
363+
.get(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
360364
.set('Cookie', context.testCredentialsUser2Cookie!);
361365

362366
expect(user2AccessUser1TeamResponse.status).toBe(403);
363367
expect(user2AccessUser1TeamResponse.body.success).toBe(false);
364368

365369
// Verify User 1's credential still exists and is accessible only to User 1
366370
const user1CredentialResponse = await request(server.server)
367-
.get(`/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
371+
.get(`/api/teams/${context.testCredentialsUser1TeamId}/cloud-credentials`)
368372
.set('Cookie', context.testCredentialsUser1Cookie!);
369373

370374
expect(user1CredentialResponse.status).toBe(200);
@@ -374,7 +378,7 @@ describe('Cloud Credentials Cross-User Permissions E2E Tests', () => {
374378

375379
// Verify User 2's team is empty (they deleted their credential)
376380
const user2CredentialResponse = await request(server.server)
377-
.get(`/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
381+
.get(`/api/teams/${context.testCredentialsUser2TeamId}/cloud-credentials`)
378382
.set('Cookie', context.testCredentialsUser2Cookie!);
379383

380384
expect(user2CredentialResponse.status).toBe(200);

0 commit comments

Comments
 (0)