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

Integration test for /yardim endpoint #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ const NodeCache = require("node-cache");
let cacheInstance;

module.exports = {
createCacheInstance: function (callback) {
createCacheInstance: function () {
if (!cacheInstance) {
cacheInstance = new NodeCache();
console.log("cache instance created");
}
},

getCache: function () {
// needed this if check for integration tests
if (!cacheInstance) {
this.createCacheInstance();
}

return cacheInstance;
},
};
40 changes: 40 additions & 0 deletions tests/unit/controller/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,44 @@ describe("Main Controller Tests", () => {
expect(response.statusCode).toBe(200);
expect(JSON.parse(response.body)["status"]).toBe("up");
});

test("/yardim", async () => {
const response = await fastify.inject({
method: "GET",
url: "/yardim",
});

expect(response.statusCode).toBe(200);

const responseBody = JSON.parse(response.body);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const responseBody = JSON.parse(response.body);
const responseBody = await response.json()


expect(responseBody).toEqual({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(responseBody).toEqual({
expect(responseBody).toDeepEqual({

next: {
page: expect.any(Number),
limit: expect.any(Number)
},
totalPage: expect.any(Number),
data: expect.any(Array),
});
expect(responseBody.data[0]).toEqual(expect.objectContaining({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

responseBody.data[]'nin length'ini de konrol edelim

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(responseBody.data[0]).toEqual(expect.objectContaining({
expect(responseBody.data[0]).toDeepEqual(expect.objectContaining({

_id: expect.any(String),
yardimTipi: expect.any(String),
adSoyad: expect.any(String),
telefon: expect.any(String),
yedekTelefonlar: expect.any(Array),
email: expect.any(String),
adres: expect.any(String),
adresTarifi: expect.any(String),
acilDurum: expect.any(String),
kisiSayisi: expect.any(String),
yardimDurumu: expect.any(String),
fizikiDurum: expect.any(String),
googleMapLink: expect.any(String),
tweetLink: expect.any(String),
fields: expect.any(Object),
createdAt: expect.any(String),
updatedAt: expect.any(String),
__v: expect.any(Number),
}))
});
});