diff --git a/cache.js b/cache.js index 8527d2b..85b5543 100644 --- a/cache.js +++ b/cache.js @@ -3,7 +3,7 @@ const NodeCache = require("node-cache"); let cacheInstance; module.exports = { - createCacheInstance: function (callback) { + createCacheInstance: function () { if (!cacheInstance) { cacheInstance = new NodeCache(); console.log("cache instance created"); @@ -11,6 +11,11 @@ module.exports = { }, getCache: function () { + // needed this if check for integration tests + if (!cacheInstance) { + this.createCacheInstance(); + } + return cacheInstance; }, }; diff --git a/tests/unit/controller/main.test.js b/tests/unit/controller/main.test.js index 178de21..8a24c1c 100644 --- a/tests/unit/controller/main.test.js +++ b/tests/unit/controller/main.test.js @@ -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); + + expect(responseBody).toEqual({ + next: { + page: expect.any(Number), + limit: expect.any(Number) + }, + totalPage: expect.any(Number), + data: expect.any(Array), + }); + expect(responseBody.data[0]).toEqual(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), + })) + }); });