Skip to content

Commit 603cb90

Browse files
committed
test(resources): expect 404 when not-found
1 parent 12c6f42 commit 603cb90

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

src/api-key/api-key.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ describe('APIKeyController (e2e)', () => {
197197
await client.post('/api/v1/api-keys').send(apiKeyData).expect(403);
198198
});
199199

200-
it('should return 403 when user tries to create API key with resource they do not have write access to', async () => {
200+
it('should return 404 when user tries to create API key with resource they do not have write access to', async () => {
201201
const apiKeyData = {
202202
user_id: client.user.id,
203203
namespace_id: client.namespace.id,
@@ -212,6 +212,6 @@ describe('APIKeyController (e2e)', () => {
212212
},
213213
};
214214

215-
await client.post('/api/v1/api-keys').send(apiKeyData).expect(403);
215+
await client.post('/api/v1/api-keys').send(apiKeyData).expect(404);
216216
});
217217
});

src/attachments/attachments.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('AttachmentsController (e2e)', () => {
114114
`/api/v1/namespaces/${client.namespace.id}/resources/${nonExistentResourceId}/attachments`,
115115
)
116116
.attach('file[]', Buffer.from(testContent), 'test.txt')
117-
.expect(403);
117+
.expect(HttpStatus.NOT_FOUND);
118118
});
119119
});
120120

src/namespace-resources/namespace-resources.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,15 @@ export class NamespaceResourcesService {
609609
}
610610

611611
async restore(userId: string, id: string) {
612-
const resource = await this.resourceRepository.findOneOrFail({
612+
const resource = await this.resourceRepository.findOne({
613613
withDeleted: true,
614614
where: {
615615
id,
616616
},
617617
});
618+
if (!resource) {
619+
throw new NotFoundException('Resource not found.');
620+
}
618621
if (resource.parentId === null) {
619622
throw new BadRequestException('Cannot restore root resource.');
620623
}

src/permissions/permissions.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ describe('PermissionsController (e2e)', () => {
7474
.expect(HttpStatus.FORBIDDEN);
7575
});
7676

77-
it('should return 403 for non-existent resource', async () => {
77+
it('should return 404 for non-existent resource', async () => {
7878
await client
7979
.get(
8080
`/api/v1/namespaces/${client.namespace.id}/resources/nonexistent/permissions`,
8181
)
82-
.expect(HttpStatus.FORBIDDEN);
82+
.expect(HttpStatus.NOT_FOUND);
8383
});
8484
});
8585

src/wizard/wizard.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ describe('WizardController (e2e)', () => {
447447
.post('/api/v1/wizard/collect')
448448
.send(collectData);
449449

450-
// Invalid parent_id results in permission error (403) rather than validation error (400)
451-
expect([HttpStatus.BAD_REQUEST, HttpStatus.FORBIDDEN]).toContain(
450+
// Invalid parent_id results in not-found error (404) rather than validation error (400)
451+
expect([HttpStatus.BAD_REQUEST, HttpStatus.NOT_FOUND]).toContain(
452452
response.status,
453453
);
454454
});

0 commit comments

Comments
 (0)