From fb3b36a56967590b72f17c2299509b374fd0cdba Mon Sep 17 00:00:00 2001
From: Alex Tran <alex.tran1502@gmail.com>
Date: Sat, 26 Nov 2022 15:09:06 -0600
Subject: [PATCH] Added test for user.service

---
 .../immich/src/api-v1/user/user.service.spec.ts     | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/server/apps/immich/src/api-v1/user/user.service.spec.ts b/server/apps/immich/src/api-v1/user/user.service.spec.ts
index abed003833..9962752cae 100644
--- a/server/apps/immich/src/api-v1/user/user.service.spec.ts
+++ b/server/apps/immich/src/api-v1/user/user.service.spec.ts
@@ -1,5 +1,5 @@
 import { UserEntity } from '@app/database/entities/user.entity';
-import { BadRequestException, NotFoundException } from '@nestjs/common';
+import { BadRequestException, NotFoundException, UnauthorizedException } from '@nestjs/common';
 import { newUserRepositoryMock } from '../../../test/test-utils';
 import { AuthUserDto } from '../../decorators/auth-user.decorator';
 import { IUserRepository } from './user-repository';
@@ -127,5 +127,16 @@ describe('UserService', () => {
       });
       expect(result).rejects.toBeInstanceOf(NotFoundException);
     });
+
+    it('cannot delete admin user', () => {
+      const requestor = adminAuthUser;
+
+      userRepositoryMock.get.mockImplementationOnce(() => Promise.resolve(adminUser));
+      userRepositoryMock.get.mockImplementationOnce(() => Promise.resolve(adminUser));
+
+      const result = sui.deleteUser(requestor, adminAuthUser.id);
+
+      expect(result).rejects.toBeInstanceOf(BadRequestException);
+    });
   });
 });