Skip to content

Commit

Permalink
test: create 1 test for generateJWT
Browse files Browse the repository at this point in the history
  • Loading branch information
arsforza committed Nov 18, 2024
1 parent 880065b commit 0816763
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions services/API-service/src/api/user/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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: '[email protected]',
whatsappNumber: '+3100000000',
username: '[email protected]',
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);
});
});
});

0 comments on commit 0816763

Please sign in to comment.