From 0816763e25b7d8cf840026d0ff105da49fa04679 Mon Sep 17 00:00:00 2001 From: arsforza Date: Mon, 18 Nov 2024 11:28:21 +0100 Subject: [PATCH] test: create 1 test for generateJWT --- .../src/api/user/user.service.spec.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 services/API-service/src/api/user/user.service.spec.ts diff --git a/services/API-service/src/api/user/user.service.spec.ts b/services/API-service/src/api/user/user.service.spec.ts new file mode 100644 index 000000000..c72159bbb --- /dev/null +++ b/services/API-service/src/api/user/user.service.spec.ts @@ -0,0 +1,65 @@ +import { + LeadTime, + LeadTimeUnit, +} from '../admin-area-dynamic-data/enum/lead-time.enum'; +import { DisasterType } from '../disaster/disaster-type.enum'; +import { DisasterEntity } from '../disaster/disaster.entity'; +import { LookupService } from '../notification/lookup/lookup.service'; +import { UserRole } from './user-role.enum'; +import { UserStatus } from './user-status.enum'; +import { UserEntity } from './user.entity'; +import { UserService } from './user.service'; + +const disasters: DisasterEntity[] = [ + { + id: '1', + disasterType: DisasterType.Floods, + label: 'Floods', + triggerUnit: 'population_affected', + actionsUnit: 'population_affected', + showOnlyTriggeredAreas: false, + countries: [], + leadTimeUnit: LeadTimeUnit.day, + minLeadTime: LeadTime.day1, + maxLeadTime: LeadTime.day7, + users: [], + }, +]; + +const user: UserEntity = { + userId: '1', + email: 'test@example.org', + whatsappNumber: '+3100000000', + username: 'test@example.org', + firstName: 'Test', + middleName: 'User', + lastName: 'Example', + userRole: UserRole.DisasterManager, + countries: [], + disasterTypes: disasters, + userStatus: UserStatus.Active, + password: '', + created: new Date(), + hashPassword: function (): void { + throw new Error('Function not implemented.'); + }, + actions: [], + stoppedTriggers: [], +}; + +describe('UserService', () => { + let userService: UserService; + + beforeEach(async () => { + userService = new UserService(new LookupService()); + }); + + describe('generateJWT', () => { + it('should generate a JWT token of type string and starting with the characters "eyJ"', async () => { + const generated = await userService.generateJWT(user); + const expectedFirstCharacters = 'eyJ'; + expect(typeof generated).toBe('string'); + expect(generated.indexOf(expectedFirstCharacters)).toBe(0); + }); + }); +});