Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fixed game tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Manueluz committed Apr 23, 2024
1 parent 22f35ed commit 2a66dfe
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 21 deletions.
38 changes: 36 additions & 2 deletions question_service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions question_service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"axios": "^1.6.8",
"axios-mock-adapter": "^1.22.0",
"bcrypt": "^5.1.1",
"chance": "^1.1.11",
"cookie-parser": "^1.4.6",
Expand Down
39 changes: 20 additions & 19 deletions question_service/question.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
const request = require('supertest')
const app = require("./question")
const MockAdapter = require('axios-mock-adapter');
const axios = require('axios');
// Mocking axios call
const mock = new MockAdapter(axios);
const responseData = {
results: {
bindings: [
{ filmLabel: { value: "Pulp Fiction" }, directorLabel: { value: "Quentin Tarantino" } },
{ filmLabel: { value: "Inception" }, directorLabel: { value: "Christopher Nolan" } },
{ filmLabel: { value: "The Shawshank Redemption" }, directorLabel: { value: "Frank Darabont" } },
{ filmLabel: { value: "The Godfather" }, directorLabel: { value: "Francis Ford Coppola" } },
{ filmLabel: { value: "The Dark Knight" }, directorLabel: { value: "Christopher Nolan" } },
{ filmLabel: { value: "Fight Club" }, directorLabel: { value: "David Fincher" } },
{ filmLabel: { value: "Forrest Gump" }, directorLabel: { value: "Robert Zemeckis" } },
{ filmLabel: { value: "The Matrix" }, directorLabel: { value: "Lana Wachowski" } }
]
}
};

mock.onAny().reply(200, responseData);

jest.mock('./db/mongo/utils', () => ({
getRandomTemplate: () => { return Promise.resolve({
Expand All @@ -14,25 +34,6 @@ jest.mock('./db/mongo/utils', () => ({
)}
}));

// Mock the fetch function
global.fetch = jest.fn().mockResolvedValue({
ok: true, // Define the 'ok' property
json: async () => ({
results: {
bindings: [
{ filmLabel: { value: "Pulp Fiction" }, directorLabel: { value: "Quentin Tarantino" } },
{ filmLabel: { value: "Inception" }, directorLabel: { value: "Christopher Nolan" } },
{ filmLabel: { value: "The Shawshank Redemption" }, directorLabel: { value: "Frank Darabont" } },
{ filmLabel: { value: "The Godfather" }, directorLabel: { value: "Francis Ford Coppola" } },
{ filmLabel: { value: "The Dark Knight" }, directorLabel: { value: "Christopher Nolan" } },
{ filmLabel: { value: "Fight Club" }, directorLabel: { value: "David Fincher" } },
{ filmLabel: { value: "Forrest Gump" }, directorLabel: { value: "Robert Zemeckis" } },
{ filmLabel: { value: "The Matrix" }, directorLabel: { value: "Lana Wachowski" } }
]
}
})
});

// Import Chance library for random number generation
const Chance = require('chance')

Expand Down

0 comments on commit 2a66dfe

Please sign in to comment.