Files
classroomio/apps/dashboard/src/lib/utils/functions/org.spec.ts
T
Toyin MuhammedandRotimi Best 6d689ede45 feat: unit tests for utils (#92)
* init

* get unit test working for course.ts file

* added some other tests

* tests halfway + change config to accomodate js files

* utility functions tests done

* fix: config file + miscellaneous fixes

* fix: prepare script

* fix lock file

---------

Co-authored-by: Rotimi Best <[email protected]>
2023-12-20 14:28:40 +03:00

61 lines
1.9 KiB
TypeScript

import { genQuizPin, generateSitename } from './org';
describe('Generate Quiz Pin', () => {
test('should return a random 6-digit pin', () => {
const result = genQuizPin();
expect(result.toString().length).toBe(6);
});
test('should return random pin each time', () => {
const result1 = genQuizPin();
const result2 = genQuizPin();
expect(result1).not.toBe(result2);
});
test('should generate a pin between 100000 and 999999', () => {
const result = genQuizPin();
expect(result).toBeGreaterThanOrEqual(100000);
expect(result).toBeLessThanOrEqual(999999);
});
test('should not generate a negative pin', () => {
const result = genQuizPin();
expect(result).toBeGreaterThanOrEqual(0);
});
test('should generate an integer pin', () => {
const result = genQuizPin();
expect(Number.isInteger(result)).toBe(true);
});
test('should not generate a zero pin', () => {
const result = genQuizPin();
expect(result).not.toBe(0);
});
});
describe('Generate Site name', () => {
test('should return slug-like string', () => {
const result = generateSitename('classroom org international');
const expected = 'classroom-org-international';
expect(result).toBe(expected);
});
test('should remove special characters', () => {
const result = generateSitename('classroom@ org! international');
const expected = 'classroom-org-international';
expect(result).toBe(expected);
});
test('should return empty string when orgName is an empty string', () => {
const result = generateSitename('');
const expected = '';
expect(result).toBe(expected);
});
test('should return slug-like string with all uppercase characters converted to lowercase', () => {
const result = generateSitename('Classroom Org International');
const expected = 'classroom-org-international';
expect(result).toBe(expected);
});
});