Skip to content

Commit

Permalink
Merge pull request #7 from laisfrigerio/hotfix/v0.1.7
Browse files Browse the repository at this point in the history
v0.1.7: remove usage of crypto lib
  • Loading branch information
laisfrigerio authored Jan 14, 2025
2 parents fce5b4d + 7262e5c commit f3cc6fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "quizland-core",
"description": "QuizLand is a tiny library with common functions to manage a quiz",
"version": "0.1.6",
"version": "0.1.7",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions src/adapters/quiz.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { randomUUID } from 'crypto';
import { QuizConfigDTO, QuestionDTO, OptionDTO } from '../dto/quiz.dto';
import { QuizConfig, Question, Option } from '../entities/quiz.entity';
import { QuizLevel, QuizMode, TypeAnswer } from '../types';

export const generateRadomString = (): string => {
return Math.random().toString().substring(2, 12);
};

const isTrainingMode = (mode: string): boolean => {
return mode === 'training';
};
Expand Down Expand Up @@ -33,7 +36,7 @@ const externalQuestionToInternal = (
): Question => {
const { answerDetails, content, options, correctAnswerIds } = question;
return {
id: randomUUID(),
id: generateRadomString(),
content,
answerDetails,
hasToShowAnswerDetails:
Expand Down Expand Up @@ -62,7 +65,7 @@ export const externalQuizConfigToInternal = (
const quizLevel: QuizLevel = level || 'easy';

return {
id: randomUUID(),
id: generateRadomString(),
title,
category,
mode: quizType,
Expand Down
7 changes: 2 additions & 5 deletions tests/adapters/quiz.adapter.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { randomUUID } from 'crypto';
import { externalQuizConfigToInternal } from '../../src/adapters/quiz.adapter';
import { QuizConfigDTO } from '../../src/dto/quiz.dto';
import { Question, QuizConfig } from '../../src/entities/quiz.entity';

jest.mock('crypto');

const id = '812df5b3-5e7c-465e-b65b-db42858e2928';
(randomUUID as jest.Mock).mockReturnValue(
'812df5b3-5e7c-465e-b65b-db42858e2928',
);
const id = '0123456789';
jest.spyOn(global.Math, 'random').mockReturnValue(0.0123456789);

const mockConfig: QuizConfigDTO = {
title: 'General Knowledge Quiz',
Expand Down

0 comments on commit f3cc6fe

Please sign in to comment.