mirror of
https://github.com/immich-app/immich.git
synced 2026-02-12 20:08:25 +03:00
fix: null validation (#25891)
This commit is contained in:
@@ -24,6 +24,34 @@ describe(AssetController.name, () => {
|
||||
await request(ctx.getHttpServer()).put(`/assets`);
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should require a valid uuid', async () => {
|
||||
const { status, body } = await request(ctx.getHttpServer())
|
||||
.put(`/assets`)
|
||||
.send({ ids: ['123'] });
|
||||
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(factory.responses.badRequest(['each value in ids must be a UUID']));
|
||||
});
|
||||
|
||||
it('should require duplicateId to be a string', async () => {
|
||||
const id = factory.uuid();
|
||||
const { status, body } = await request(ctx.getHttpServer())
|
||||
.put(`/assets`)
|
||||
.send({ ids: [id], duplicateId: true });
|
||||
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(factory.responses.badRequest(['duplicateId must be a string']));
|
||||
});
|
||||
|
||||
it('should accept a null duplicateId', async () => {
|
||||
const id = factory.uuid();
|
||||
await request(ctx.getHttpServer())
|
||||
.put(`/assets`)
|
||||
.send({ ids: [id], duplicateId: null });
|
||||
|
||||
expect(service.updateAll).toHaveBeenCalledWith(undefined, expect.objectContaining({ duplicateId: null }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /assets', () => {
|
||||
|
||||
36
server/src/controllers/notification-admin.controller.spec.ts
Normal file
36
server/src/controllers/notification-admin.controller.spec.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { NotificationAdminController } from 'src/controllers/notification-admin.controller';
|
||||
import { NotificationAdminService } from 'src/services/notification-admin.service';
|
||||
import request from 'supertest';
|
||||
import { factory } from 'test/small.factory';
|
||||
import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils';
|
||||
|
||||
describe(NotificationAdminController.name, () => {
|
||||
let ctx: ControllerContext;
|
||||
const service = mockBaseService(NotificationAdminService);
|
||||
|
||||
beforeAll(async () => {
|
||||
ctx = await controllerSetup(NotificationAdminController, [
|
||||
{ provide: NotificationAdminService, useValue: service },
|
||||
]);
|
||||
return () => ctx.close();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service.resetAllMocks();
|
||||
ctx.reset();
|
||||
});
|
||||
|
||||
describe('POST /admin/notifications', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).post('/admin/notifications');
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should accept a null readAt', async () => {
|
||||
await request(ctx.getHttpServer())
|
||||
.post(`/admin/notifications`)
|
||||
.send({ title: 'Test', userId: factory.uuid(), readAt: null });
|
||||
expect(service.create).toHaveBeenCalledWith(undefined, expect.objectContaining({ readAt: null }));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -37,9 +37,33 @@ describe(NotificationController.name, () => {
|
||||
|
||||
describe('PUT /notifications', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).get('/notifications');
|
||||
await request(ctx.getHttpServer()).put('/notifications');
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('ids', () => {
|
||||
it('should require a list', async () => {
|
||||
const { status, body } = await request(ctx.getHttpServer()).put(`/notifications`).send({ ids: true });
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(errorDto.badRequest(expect.arrayContaining(['ids must be an array'])));
|
||||
});
|
||||
|
||||
it('should require uuids', async () => {
|
||||
const { status, body } = await request(ctx.getHttpServer())
|
||||
.put(`/notifications`)
|
||||
.send({ ids: [true] });
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(errorDto.badRequest(['each value in ids must be a UUID']));
|
||||
});
|
||||
|
||||
it('should accept valid uuids', async () => {
|
||||
const id = factory.uuid();
|
||||
await request(ctx.getHttpServer())
|
||||
.put(`/notifications`)
|
||||
.send({ ids: [id] });
|
||||
expect(service.updateAll).toHaveBeenCalledWith(undefined, expect.objectContaining({ ids: [id] }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /notifications/:id', () => {
|
||||
@@ -60,5 +84,11 @@ describe(NotificationController.name, () => {
|
||||
await request(ctx.getHttpServer()).put(`/notifications/${factory.uuid()}`).send({ readAt: factory.date() });
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should accept a null readAt', async () => {
|
||||
const id = factory.uuid();
|
||||
await request(ctx.getHttpServer()).put(`/notifications/${id}`).send({ readAt: null });
|
||||
expect(service.update).toHaveBeenCalledWith(undefined, id, expect.objectContaining({ readAt: null }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,6 +58,11 @@ describe(PersonController.name, () => {
|
||||
await request(ctx.getHttpServer()).post('/people').send({ birthDate: '' });
|
||||
expect(service.create).toHaveBeenCalledWith(undefined, { birthDate: null });
|
||||
});
|
||||
|
||||
it('should map an empty color to null', async () => {
|
||||
await request(ctx.getHttpServer()).post('/people').send({ color: '' });
|
||||
expect(service.create).toHaveBeenCalledWith(undefined, { color: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /people', () => {
|
||||
|
||||
34
server/src/controllers/shared-link.controller.spec.ts
Normal file
34
server/src/controllers/shared-link.controller.spec.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { SharedLinkController } from 'src/controllers/shared-link.controller';
|
||||
import { SharedLinkType } from 'src/enum';
|
||||
import { SharedLinkService } from 'src/services/shared-link.service';
|
||||
import request from 'supertest';
|
||||
import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils';
|
||||
|
||||
describe(SharedLinkController.name, () => {
|
||||
let ctx: ControllerContext;
|
||||
const service = mockBaseService(SharedLinkService);
|
||||
|
||||
beforeAll(async () => {
|
||||
ctx = await controllerSetup(SharedLinkController, [{ provide: SharedLinkService, useValue: service }]);
|
||||
return () => ctx.close();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service.resetAllMocks();
|
||||
ctx.reset();
|
||||
});
|
||||
|
||||
describe('POST /shared-links', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).post('/shared-links');
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should allow an null expiresAt', async () => {
|
||||
await request(ctx.getHttpServer())
|
||||
.post('/shared-links')
|
||||
.send({ expiresAt: null, type: SharedLinkType.Individual });
|
||||
expect(service.create).toHaveBeenCalledWith(undefined, expect.objectContaining({ expiresAt: null }));
|
||||
});
|
||||
});
|
||||
});
|
||||
73
server/src/controllers/tag.controller.spec.ts
Normal file
73
server/src/controllers/tag.controller.spec.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { TagController } from 'src/controllers/tag.controller';
|
||||
import { TagService } from 'src/services/tag.service';
|
||||
import request from 'supertest';
|
||||
import { errorDto } from 'test/medium/responses';
|
||||
import { factory } from 'test/small.factory';
|
||||
import { ControllerContext, controllerSetup, mockBaseService } from 'test/utils';
|
||||
|
||||
describe(TagController.name, () => {
|
||||
let ctx: ControllerContext;
|
||||
const service = mockBaseService(TagService);
|
||||
|
||||
beforeAll(async () => {
|
||||
ctx = await controllerSetup(TagController, [{ provide: TagService, useValue: service }]);
|
||||
return () => ctx.close();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service.resetAllMocks();
|
||||
ctx.reset();
|
||||
});
|
||||
|
||||
describe('GET /tags', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).get('/tags');
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /tags', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).post('/tags');
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should a null parentId', async () => {
|
||||
await request(ctx.getHttpServer()).post(`/tags`).send({ name: 'tag', parentId: null });
|
||||
expect(service.create).toHaveBeenCalledWith(undefined, expect.objectContaining({ parentId: null }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /tags', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).put('/tags');
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /tags/:id', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).get(`/tags/${factory.uuid()}`);
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should require a valid uuid', async () => {
|
||||
const { status, body } = await request(ctx.getHttpServer()).get(`/tags/123`);
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(errorDto.badRequest([expect.stringContaining('id must be a UUID')]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /tags/:id', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).put(`/tags/${factory.uuid()}`);
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should allow setting a null color via an empty string', async () => {
|
||||
const id = factory.uuid();
|
||||
await request(ctx.getHttpServer()).put(`/tags/${id}`).send({ color: '' });
|
||||
expect(service.update).toHaveBeenCalledWith(undefined, id, expect.objectContaining({ color: null }));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -31,12 +31,55 @@ describe(UserAdminController.name, () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /admin/users/:id', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).put(`/admin/users/${factory.uuid()}`);
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /admin/users', () => {
|
||||
it('should be an authenticated route', async () => {
|
||||
await request(ctx.getHttpServer()).post('/admin/users');
|
||||
expect(ctx.authenticate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should allow a null pinCode', async () => {
|
||||
await request(ctx.getHttpServer()).post(`/admin/users`).send({
|
||||
name: 'Test user',
|
||||
email: 'test@immich.cloud',
|
||||
password: 'password',
|
||||
pinCode: null,
|
||||
});
|
||||
expect(service.create).toHaveBeenCalledWith(expect.objectContaining({ pinCode: null }));
|
||||
});
|
||||
|
||||
it('should allow a null avatarColor', async () => {
|
||||
await request(ctx.getHttpServer()).post(`/admin/users`).send({
|
||||
name: 'Test user',
|
||||
email: 'test@immich.cloud',
|
||||
password: 'password',
|
||||
avatarColor: null,
|
||||
});
|
||||
expect(service.create).toHaveBeenCalledWith(expect.objectContaining({ avatarColor: null }));
|
||||
});
|
||||
|
||||
it(`should `, async () => {
|
||||
const dto: UserAdminCreateDto = {
|
||||
email: 'user@immich.app',
|
||||
password: 'test',
|
||||
name: 'Test User',
|
||||
quotaSizeInBytes: 1.2,
|
||||
};
|
||||
|
||||
const { status, body } = await request(ctx.getHttpServer())
|
||||
.post(`/admin/users`)
|
||||
.set('Authorization', `Bearer token`)
|
||||
.send(dto);
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(errorDto.badRequest(expect.arrayContaining(['quotaSizeInBytes must be an integer number'])));
|
||||
});
|
||||
|
||||
it(`should not allow decimal quota`, async () => {
|
||||
const dto: UserAdminCreateDto = {
|
||||
email: 'user@immich.app',
|
||||
@@ -75,5 +118,17 @@ describe(UserAdminController.name, () => {
|
||||
expect(status).toBe(400);
|
||||
expect(body).toEqual(errorDto.badRequest(expect.arrayContaining(['quotaSizeInBytes must be an integer number'])));
|
||||
});
|
||||
|
||||
it('should allow a null pinCode', async () => {
|
||||
const id = factory.uuid();
|
||||
await request(ctx.getHttpServer()).put(`/admin/users/${id}`).send({ pinCode: null });
|
||||
expect(service.update).toHaveBeenCalledWith(undefined, id, expect.objectContaining({ pinCode: null }));
|
||||
});
|
||||
|
||||
it('should allow a null avatarColor', async () => {
|
||||
const id = factory.uuid();
|
||||
await request(ctx.getHttpServer()).put(`/admin/users/${id}`).send({ avatarColor: null });
|
||||
expect(service.update).toHaveBeenCalledWith(undefined, id, expect.objectContaining({ avatarColor: null }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,6 +54,14 @@ describe(UserController.name, () => {
|
||||
expect(body).toEqual(errorDto.badRequest());
|
||||
});
|
||||
}
|
||||
|
||||
it('should allow an empty avatarColor', async () => {
|
||||
await request(ctx.getHttpServer())
|
||||
.put(`/users/me`)
|
||||
.set('Authorization', `Bearer token`)
|
||||
.send({ avatarColor: null });
|
||||
expect(service.updateMe).toHaveBeenCalledWith(undefined, expect.objectContaining({ avatarColor: null }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /users/:id', () => {
|
||||
|
||||
Reference in New Issue
Block a user