generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: creating the questions.js tests.
- v1.7.1.3
- v1.7.1.2
- v1.7.1.1
- v1.7.1
- v1.7.0
- v1.6.0.1
- v1.6.0
- v1.5.4.5
- v1.5.4.4
- v1.5.4.3
- v1.5.4.2
- v1.5.4.1
- v1.5.4
- v1.5.3.8
- v1.5.3.7
- v1.5.3.6
- v1.5.3.5
- v1.5.3.4
- v1.5.3.3
- v1.5.3.2
- v1.5.3.1
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3.1
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.1-httpsFix
- v1.3.1-https
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- 1.4.4.1
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import MockAdapter from "axios-mock-adapter"; | ||
import { getQuestion, answerQuestion } from "components/game/Questions"; | ||
import axios, { HttpStatusCode } from "axios"; | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
|
||
describe("Question Service tests", () => { | ||
describe("getQuestion function", () => { | ||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it("successfully retrieves a question", async () => { | ||
// Mock axios | ||
const mockQuestion = { | ||
questionId: 123, | ||
text: "What is the meaning of life?", | ||
}; | ||
|
||
mockAxios.onGet(process.env.REACT_APP_API_ENDPOINT + "/questions/new").replyOnce( | ||
HttpStatusCode.Ok, | ||
mockQuestion | ||
); | ||
|
||
const result = await getQuestion(); | ||
|
||
expect(result).toEqual(mockQuestion); | ||
}); | ||
}); | ||
|
||
describe("answerQuestion function", () => { | ||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it("successfully answers a question", async () => { | ||
const mockResponse = { | ||
success: true, | ||
message: "Answer submitted successfully.", | ||
}; | ||
|
||
mockAxios.onPost(process.env.REACT_APP_API_ENDPOINT + "/questions/123/answer").replyOnce( | ||
HttpStatusCode.Ok, | ||
mockResponse | ||
); | ||
|
||
const result = await answerQuestion(123, "a1"); | ||
|
||
expect(result).toEqual(mockResponse); | ||
}); | ||
}); | ||
}); |