Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored unit tests for routers #214

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/api/src/functions/gptHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export const parseMultiselectResponse = (
};
};

//This is a horrible implementaion but atleast all question types are the same objects and attributes
export const parseIdentificationResponse = (
generatedMessage: string,
): IdentificationPrompt => {
Expand Down Expand Up @@ -265,6 +266,7 @@ export const parseIdentificationResponse = (
};
};

//This is a horrible implementaion but atleast all question types are the same objects and attributes
export const parseTrueOrFalseResponse = (
generatedMessage: string,
): TrueOrFalsePrompt => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ ${timeAndPointsPrompt}`,
);
});

// Test for custom parameters for the identification type
it("should generate prompt for identification with custom max characters", () => {
const result = generatePromptForType(message, "identification", 90, 60);
expect(result).toEqual(
Expand Down
44 changes: 33 additions & 11 deletions packages/api/src/functions/tests/parseQuestionTypeResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe("parseIdentificationResponse", () => {
const result = parseIdentificationResponse(generatedMessage);
expect(result).toEqual({
question: "Who was the first president of the United States?",
answer: "George Washington",
choices: [{ text: "George Washington", isCorrect: true }],
timeLimit: 10,
points: 100,
type: "identification",
Expand All @@ -347,9 +347,10 @@ describe("parseIdentificationResponse", () => {
Points: 200
`;
const result = parseIdentificationResponse(generatedMessage);

expect(result).toEqual({
question: "",
answer: "George Washington",
choices: [{ text: "George Washington", isCorrect: true }],
timeLimit: 20,
points: 200,
type: "identification",
Expand All @@ -365,7 +366,7 @@ describe("parseIdentificationResponse", () => {
const result = parseIdentificationResponse(generatedMessage);
expect(result).toEqual({
question: "Who was the first president of the United States?",
answer: "",
choices: [{ text: "", isCorrect: true }],
timeLimit: 30,
points: 300,
type: "identification",
Expand All @@ -377,7 +378,7 @@ describe("parseIdentificationResponse", () => {
const result = parseIdentificationResponse(generatedMessage);
expect(result).toEqual({
question: "",
answer: "",
choices: [{ text: "", isCorrect: true }],
timeLimit: 0,
points: 0,
type: "identification",
Expand All @@ -396,7 +397,10 @@ describe("parseTrueOrFalseResponse", () => {
const result = parseTrueOrFalseResponse(generatedMessage);
expect(result).toEqual({
question: "Is the sky blue?",
answer: true,
choices: [
{ text: "True", isCorrect: true },
{ text: "False", isCorrect: false },
],
timeLimit: 30,
points: 5,
type: "trueOrFalse",
Expand All @@ -413,7 +417,10 @@ describe("parseTrueOrFalseResponse", () => {
const result = parseTrueOrFalseResponse(generatedMessage);
expect(result).toEqual({
question: "Do cows fly?",
answer: false,
choices: [
{ text: "True", isCorrect: false },
{ text: "False", isCorrect: true },
],
timeLimit: 45,
points: 10,
type: "trueOrFalse",
Expand All @@ -427,7 +434,10 @@ describe("parseTrueOrFalseResponse", () => {
const result = parseTrueOrFalseResponse(generatedMessage);
expect(result).toEqual({
question: "",
answer: false,
choices: [
{ text: "True", isCorrect: false },
{ text: "False", isCorrect: true },
],
timeLimit: 0,
points: 0,
type: "trueOrFalse",
Expand All @@ -441,7 +451,10 @@ describe("parseTrueOrFalseResponse", () => {
const result = parseTrueOrFalseResponse(generatedMessage);
expect(result).toEqual({
question: "Do cows fly?",
answer: false, // defaults to false
choices: [
{ text: "True", isCorrect: false },
{ text: "False", isCorrect: true },
],
timeLimit: 0,
points: 0,
type: "trueOrFalse",
Expand All @@ -456,7 +469,10 @@ describe("parseTrueOrFalseResponse", () => {
const result = parseTrueOrFalseResponse(generatedMessage);
expect(result).toEqual({
question: "Is the sky blue?",
answer: true,
choices: [
{ text: "True", isCorrect: true },
{ text: "False", isCorrect: false },
],
timeLimit: 0,
points: 0,
type: "trueOrFalse",
Expand All @@ -468,7 +484,10 @@ describe("parseTrueOrFalseResponse", () => {
const result = parseTrueOrFalseResponse(generatedMessage);
expect(result).toEqual({
question: "",
answer: false, // defaults to false
choices: [
{ text: "True", isCorrect: false },
{ text: "False", isCorrect: true },
],
timeLimit: 0,
points: 0,
type: "trueOrFalse",
Expand All @@ -483,7 +502,10 @@ describe("parseTrueOrFalseResponse", () => {
const result = parseTrueOrFalseResponse(generatedMessage);
expect(result).toEqual({
question: "Is the sun hot?",
answer: true,
choices: [
{ text: "True", isCorrect: true },
{ text: "False", isCorrect: false },
],
timeLimit: 0,
points: 0,
type: "trueOrFalse",
Expand Down
Loading
Loading