diff --git a/jest.config.js b/jest.config.js index 7442fda..ddd79ef 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,10 +1,18 @@ module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', + preset: "ts-jest", + testEnvironment: "node", transform: { - '^.+\\.tsx?$': 'ts-jest' + "^.+\\.tsx?$": "ts-jest" }, - testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(tsx?)$', - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - clearMocks: true + testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(tsx?)$", + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], + modulePathIgnorePatterns: ["./.wrappid", "./build"], + clearMocks: true, + collectCoverage: true, + collectCoverageFrom: [ + "test/**/*.{js,jsx,ts}", + "!**/node_modules/**" + + + ], }; \ No newline at end of file diff --git a/package.json b/package.json index ad48b92..c227538 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "@commitlint/config-conventional": "~17.4.4", "@commitlint/prompt-cli": "~17.5.0", "@faker-js/faker": "~8.1.0", - "@types/supertest": "^6.0.2", + "@jest/globals": "~29.7.0", + "@types/supertest": "~6.0.2", "@wrappid/core": "latest", "@wrappid/service-core": "latest", "@wrappid/styles": "latest", @@ -56,9 +57,9 @@ "jest": "~29.7.0", "license-checker": "~25.0.1", "react-redux": "~8.0.5", + "standard-version": "~9.5.0", "supertest": "~6.3.3", - "yup": "~1.3.3", "ts-jest": "~29.1.2", - "standard-version": "~9.5.0" + "yup": "~1.3.3" } } diff --git a/service/test/addressType.test.ts b/service/test/addressType.test.ts new file mode 100644 index 0000000..d0d179d --- /dev/null +++ b/service/test/addressType.test.ts @@ -0,0 +1,154 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +import { beforeAll,describe, test, expect } from "@jest/globals"; +import request from "supertest"; + +const BASE_URL = "http://localhost:8080/"; + +let token = ""; +// eslint-disable-next-line no-undef +beforeAll (async () => { + const response = await request(BASE_URL) + .post("login") + .send({ emailOrPhone: "pritam@rxefy.com", password: "Pritam@rxefy123" }) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + token = response.body.accessToken; +}); +describe("Test: addressType",() => { + test("TC01 Verify API Response Status Code", async () => { + const response = await request(BASE_URL) + + .get("addressType") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "(Windows 11; Win64; x64) Version 123.0.6312.106 (Official Build) (64-bit)"); + + expect(response.statusCode).toBe(200); + }); + test("TC02 Verify API Response Format JSON", async () => { + const response = await request(BASE_URL) + .get("addressType") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.body).toBeInstanceOf(Object); + }); + + test("TC05 Verify API Response Time Within Acceptable Limits", async () => { + const acceptableResponseTime = 2000; + const startTime = Date.now(); + await request(BASE_URL) + .get("addressType") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const endTime = Date.now(); + const responseTime = endTime - startTime; + expect(responseTime).toBeLessThanOrEqual(acceptableResponseTime); //responsetime = 152ms as of now + }); + + // eslint-disable-next-line @typescript-eslint/no-empty-function + test("TC08 Verify API Endpoint URL", async () => { + }); + + test("TC09 Verify API Response Headers", async () => { + const response = await request(BASE_URL) + .get("addressType") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.headers["content-type"]).toBe("application/json; charset=utf-8"); + expect(response.headers["access-control-allow-origin"]).toBe("*"); + expect(response.headers["connection"]).toBe("keep-alive"); + }); + + test("TC10 Verify API Response Payload Size", async () => { + const response = await request(BASE_URL) + .get("addressType") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const payloadSize = Buffer.from(JSON.stringify(response.body)).length; + const maxSize = 5000; // Set the maximum allowed payload size in bytes + expect(payloadSize).toBeLessThanOrEqual(maxSize); + }); + + test("TC11 Verify API Handles Malformed Requests", async () => { + }); + + test("TC12 Verify API Handles Authentication Failure", async () => { + }); + + test("TC13 Verify API Handles Missing Request Payload", async () => { + }); + + test("TC15 Verify API Handles Unauthorized Access", async () => { + function generateRandomString(length: number): string { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; + } + const falsetoken = generateRandomString(20); + //const falsetoken = "JyotirmoyGhosh1610"; + const response = await request(BASE_URL) + .get("addressType") + .set("Authorization", `Bearer ${falsetoken}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.statusCode).toBe(401); + }); + + test("TC16 Verify API Handles Request Payload Size Limit", async () => { + }); + + test("TC18 Verify API Handles Invalid Request Method", async () => { + }); + + test("TC38 Verify API Response Content Type", async () => { + const response = await request(BASE_URL) + .get("addressType") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.header["content-type"]).toContain("application/json"); + }); + + test("TC39 Verify API Response Compression (Accept-Encoding)", async () => { + }); + + test("TC41 Verify API Response Not Compressed (Other Encoding)", async () => { + }); + + test("TC42 Verify API Response Language (Accept-Language)", async () => { + }); + + test("TC43 Verify API Response Locale", async () => { + }); + + test("TC44 Verify API Response Timezone (Accept-Timezone)", async () => { + }); +}); + diff --git a/service/test/department.test.ts b/service/test/department.test.ts new file mode 100644 index 0000000..db0251f --- /dev/null +++ b/service/test/department.test.ts @@ -0,0 +1,153 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +import { beforeAll,describe, test, expect } from "@jest/globals"; +import request from "supertest"; + +const BASE_URL = "http://localhost:8080/"; + +let token = ""; +// eslint-disable-next-line no-undef +beforeAll (async () => { + const response = await request(BASE_URL) + .post("login") + .send({ emailOrPhone: "pritam@rxefy.com", password: "Pritam@rxefy123" }) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + token = response.body.accessToken; +}); +describe("Test: department",() => { + test("TC01 Verify API Response Status Code", async () => { + const response = await request(BASE_URL) + + .get("department") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "(Windows 11; Win64; x64) Version 123.0.6312.106 (Official Build) (64-bit)"); + + expect(response.statusCode).toBe(200); + }); + test("TC02 Verify API Response Format JSON", async () => { + const response = await request(BASE_URL) + .get("department") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.body).toBeInstanceOf(Object); + }); + + test("TC05 Verify API Response Time Within Acceptable Limits", async () => { + const acceptableResponseTime = 2000; + const startTime = Date.now(); + await request(BASE_URL) + .get("department") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const endTime = Date.now(); + const responseTime = endTime - startTime; + expect(responseTime).toBeLessThanOrEqual(acceptableResponseTime); //responsetime = 152ms as of now + }); + + // eslint-disable-next-line @typescript-eslint/no-empty-function + test("TC08 Verify API Endpoint URL", async () => { + }); + + test("TC09 Verify API Response Headers", async () => { + const response = await request(BASE_URL) + .get("department") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.headers["content-type"]).toBe("application/json; charset=utf-8"); + expect(response.headers["access-control-allow-origin"]).toBe("*"); + expect(response.headers["connection"]).toBe("keep-alive"); + }); + + test("TC10 Verify API Response Payload Size", async () => { + const response = await request(BASE_URL) + .get("department") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const payloadSize = Buffer.from(JSON.stringify(response.body)).length; + const maxSize = 15000; // Set the maximum allowed payload size in bytes + expect(payloadSize).toBeLessThanOrEqual(maxSize); + }); + + test("TC11 Verify API Handles Malformed Requests", async () => { + }); + + test("TC12 Verify API Handles Authentication Failure", async () => { + }); + + test("TC13 Verify API Handles Missing Request Payload", async () => { + }); + + test("TC15 Verify API Handles Unauthorized Access", async () => { + function generateRandomString(length: number): string { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; + } + const falsetoken = generateRandomString(20); + //const falsetoken = "JyotirmoyGhosh1610"; + const response = await request(BASE_URL) + .get("department") + .set("Authorization", `Bearer ${falsetoken}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.statusCode).toBe(401); + }); + + test("TC16 Verify API Handles Request Payload Size Limit", async () => { + }); + + test("TC18 Verify API Handles Invalid Request Method", async () => { + }); + + test("TC38 Verify API Response Content Type", async () => { + const response = await request(BASE_URL) + .get("department") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.header["content-type"]).toContain("application/json"); + }); + + test("TC39 Verify API Response Compression (Accept-Encoding)", async () => { + }); + + test("TC41 Verify API Response Not Compressed (Other Encoding)", async () => { + }); + + test("TC42 Verify API Response Language (Accept-Language)", async () => { + }); + + test("TC43 Verify API Response Locale", async () => { + }); + + test("TC44 Verify API Response Timezone (Accept-Timezone)", async () => { + }); +}); \ No newline at end of file diff --git a/service/test/personContactsContactType.test.ts b/service/test/personContactsContactType.test.ts new file mode 100644 index 0000000..70599fb --- /dev/null +++ b/service/test/personContactsContactType.test.ts @@ -0,0 +1,165 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +import { beforeAll,describe, test, expect } from "@jest/globals"; +import request from "supertest"; + +const BASE_URL = "http://localhost:8080/"; + +let token = ""; +// eslint-disable-next-line no-undef +beforeAll (async () => { + const response = await request(BASE_URL) + .post("login") + .send({ emailOrPhone: "pritam@rxefy.com", password: "Pritam@rxefy123" }) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + token = response.body.accessToken; +}); +describe("Test: personContacts/:contactType",() => { + test("TC01 Verify API Response Status Code", async () => { + const contactType = "email"; + const response = await request(BASE_URL) + + .get(`personContacts/${contactType}`) + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "(Windows 11; Win64; x64) Version 123.0.6312.106 (Official Build) (64-bit)"); + + expect(response.statusCode).toBe(200); + }); + test("TC02 Verify API Response Format JSON", async () => { + const contactType = "email"; + const response = await request(BASE_URL) + .get(`personContacts/${contactType}`) + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.body).toBeInstanceOf(Object); + }); + + test("TC05 Verify API Response Time Within Acceptable Limits", async () => { + const contactType = "email"; + const acceptableResponseTime = 2000; + const startTime = Date.now(); + await request(BASE_URL) + .get(`personContacts/${contactType}`) + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const endTime = Date.now(); + const responseTime = endTime - startTime; + expect(responseTime).toBeLessThanOrEqual(acceptableResponseTime); //responsetime = 152ms as of now + }); + + // eslint-disable-next-line @typescript-eslint/no-empty-function + test("TC08 Verify API Endpoint URL", async () => { + }); + + test("TC09 Verify API Response Headers", async () => { + const contactType = "eamil"; + const response = await request(BASE_URL) + .get(`personContacts/${contactType}`) + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + //expect(response.headers["content-type"]).toBe("application/json; charset=utf-8"); + /* + status was 204 (no content) + @todo + + */ + expect(response.headers["access-control-allow-origin"]).toBe("*"); + expect(response.headers["connection"]).toBe("keep-alive"); + }); + + test("TC10 Verify API Response Payload Size", async () => { + const contactType = "email"; + const response = await request(BASE_URL) + .get(`personContacts/${contactType}`) + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const payloadSize = Buffer.from(JSON.stringify(response.body)).length; + const maxSize = 5000; // Set the maximum allowed payload size in bytes + expect(payloadSize).toBeLessThanOrEqual(maxSize); + }); + + test("TC11 Verify API Handles Malformed Requests", async () => { + }); + + test("TC12 Verify API Handles Authentication Failure", async () => { + }); + + test("TC13 Verify API Handles Missing Request Payload", async () => { + }); + + test("TC15 Verify API Handles Unauthorized Access", async () => { + const contactType = "email"; + function generateRandomString(length: number): string { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; + } + const falsetoken = generateRandomString(20); + //const falsetoken = "JyotirmoyGhosh1610"; + const response = await request(BASE_URL) + .get(`personContacts/${contactType}`) + .set("Authorization", `Bearer ${falsetoken}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.statusCode).toBe(401); + }); + + test("TC16 Verify API Handles Request Payload Size Limit", async () => { + }); + + test("TC18 Verify API Handles Invalid Request Method", async () => { + }); + + test("TC38 Verify API Response Content Type", async () => { + const contactType = "email"; + const response = await request(BASE_URL) + .get(`personContacts/${contactType}`) + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.header["content-type"]).toContain("application/json"); + }); + + test("TC39 Verify API Response Compression (Accept-Encoding)", async () => { + }); + + test("TC41 Verify API Response Not Compressed (Other Encoding)", async () => { + }); + + test("TC42 Verify API Response Language (Accept-Language)", async () => { + }); + + test("TC43 Verify API Response Locale", async () => { + }); + + test("TC44 Verify API Response Timezone (Accept-Timezone)", async () => { + }); +}); diff --git a/service/test/rxContactInfo.test.ts b/service/test/rxContactInfo.test.ts new file mode 100644 index 0000000..bb73913 --- /dev/null +++ b/service/test/rxContactInfo.test.ts @@ -0,0 +1,153 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +import { beforeAll,describe, test, expect } from "@jest/globals"; +import request from "supertest"; + +const BASE_URL = "http://localhost:8080/"; + +let token = ""; +// eslint-disable-next-line no-undef +beforeAll (async () => { + const response = await request(BASE_URL) + .post("login") + .send({ emailOrPhone: "pritam@rxefy.com", password: "Pritam@rxefy123" }) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + token = response.body.accessToken; +}); +describe("Test: rx/contactInfo",() => { + test("TC01 Verify API Response Status Code", async () => { + const response = await request(BASE_URL) + + .get("rx/contactInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "(Windows 11; Win64; x64) Version 123.0.6312.106 (Official Build) (64-bit)"); + + expect(response.statusCode).toBe(200); + }); + test("TC02 Verify API Response Format JSON", async () => { + const response = await request(BASE_URL) + .get("rx/contactInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.body).toBeInstanceOf(Object); + }); + + test("TC05 Verify API Response Time Within Acceptable Limits", async () => { + const acceptableResponseTime = 2000; + const startTime = Date.now(); + await request(BASE_URL) + .get("rx/contactInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const endTime = Date.now(); + const responseTime = endTime - startTime; + expect(responseTime).toBeLessThanOrEqual(acceptableResponseTime); //responsetime = 152ms as of now + }); + + // eslint-disable-next-line @typescript-eslint/no-empty-function + test("TC08 Verify API Endpoint URL", async () => { + }); + + test("TC09 Verify API Response Headers", async () => { + const response = await request(BASE_URL) + .get("rx/contactInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.headers["content-type"]).toBe("application/json; charset=utf-8"); + expect(response.headers["access-control-allow-origin"]).toBe("*"); + expect(response.headers["connection"]).toBe("keep-alive"); + }); + + test("TC10 Verify API Response Payload Size", async () => { + const response = await request(BASE_URL) + .get("rx/contactInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const payloadSize = Buffer.from(JSON.stringify(response.body)).length; + const maxSize = 5000; // Set the maximum allowed payload size in bytes + expect(payloadSize).toBeLessThanOrEqual(maxSize); + }); + + test("TC11 Verify API Handles Malformed Requests", async () => { + }); + + test("TC12 Verify API Handles Authentication Failure", async () => { + }); + + test("TC13 Verify API Handles Missing Request Payload", async () => { + }); + + test("TC15 Verify API Handles Unauthorized Access", async () => { + function generateRandomString(length: number): string { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; + } + const falsetoken = generateRandomString(20); + //const falsetoken = "JyotirmoyGhosh1610"; + const response = await request(BASE_URL) + .get("rx/contactInfo") + .set("Authorization", `Bearer ${falsetoken}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.statusCode).toBe(401); + }); + + test("TC16 Verify API Handles Request Payload Size Limit", async () => { + }); + + test("TC18 Verify API Handles Invalid Request Method", async () => { + }); + + test("TC38 Verify API Response Content Type", async () => { + const response = await request(BASE_URL) + .get("rx/contactInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.header["content-type"]).toContain("application/json"); + }); + + test("TC39 Verify API Response Compression (Accept-Encoding)", async () => { + }); + + test("TC41 Verify API Response Not Compressed (Other Encoding)", async () => { + }); + + test("TC42 Verify API Response Language (Accept-Language)", async () => { + }); + + test("TC43 Verify API Response Locale", async () => { + }); + + test("TC44 Verify API Response Timezone (Accept-Timezone)", async () => { + }); +}); \ No newline at end of file diff --git a/service/test/rxRegistrationInfo.test.ts b/service/test/rxRegistrationInfo.test.ts new file mode 100644 index 0000000..3d8b32e --- /dev/null +++ b/service/test/rxRegistrationInfo.test.ts @@ -0,0 +1,156 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +import { beforeAll,describe, test, expect } from "@jest/globals"; +import request from "supertest"; + +const BASE_URL = "http://localhost:8080/"; + +let token = ""; +// eslint-disable-next-line no-undef +beforeAll (async () => { + const response = await request(BASE_URL) + .post("login") + .send({ emailOrPhone: "pritam@rxefy.com", password: "Pritam@rxefy123" }) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + token = response.body.accessToken; +}); +describe("Test: rx/registrationInfo",() => { + test("TC01 Verify API Response Status Code", async () => { + const response = await request(BASE_URL) + + .get("rx/registrationInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "(Windows 11; Win64; x64) Version 123.0.6312.106 (Official Build) (64-bit)"); + + expect(response.statusCode).toBe(204); //As there is no content available aganist this login ID + //expect(response.statusCode).toBe(200); + }); + test("TC02 Verify API Response Format JSON", async () => { + const response = await request(BASE_URL) + .get("rx/registrationInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.body).toBeInstanceOf(Object); + }); + + test("TC05 Verify API Response Time Within Acceptable Limits", async () => { + const acceptableResponseTime = 2000; + const startTime = Date.now(); + await request(BASE_URL) + .get("rx/registrationInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const endTime = Date.now(); + const responseTime = endTime - startTime; + expect(responseTime).toBeLessThanOrEqual(acceptableResponseTime); //responsetime = 152ms as of now + }); + + // eslint-disable-next-line @typescript-eslint/no-empty-function + test("TC08 Verify API Endpoint URL", async () => { + }); + + test("TC09 Verify API Response Headers", async () => { + const response = await request(BASE_URL) + .get("rx/contactInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + expect(response.headers["content-type"]).toBe("application/json; charset=utf-8"); + expect(response.headers["access-control-allow-origin"]).toBe("*"); + expect(response.headers["connection"]).toBe("keep-alive"); + }); + + test("TC10 Verify API Response Payload Size", async () => { + const response = await request(BASE_URL) + .get("rx/registrationInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + + const payloadSize = Buffer.from(JSON.stringify(response.body)).length; + const maxSize = 5000; // Set the maximum allowed payload size in bytes + expect(payloadSize).toBeLessThanOrEqual(maxSize); + }); + + test("TC11 Verify API Handles Malformed Requests", async () => { + }); + + test("TC12 Verify API Handles Authentication Failure", async () => { + }); + + test("TC13 Verify API Handles Missing Request Payload", async () => { + }); + + test("TC15 Verify API Handles Unauthorized Access", async () => { + function generateRandomString(length: number): string { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; + } + const falsetoken = generateRandomString(20); + //const falsetoken = "JyotirmoyGhosh1610"; + const response = await request(BASE_URL) + .get("rx/registrationInfo") + .set("Authorization", `Bearer ${falsetoken}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + expect(response.statusCode).toBe(401); + }); + + test("TC16 Verify API Handles Request Payload Size Limit", async () => { + }); + + test("TC18 Verify API Handles Invalid Request Method", async () => { + }); + + test("TC38 Verify API Response Content Type", async () => { + const response = await request(BASE_URL) + .get("rx/registrationInfo") + .set("Authorization", `Bearer ${token}`) + .set("Content-Type", "application/json") + .set("Accept-Encoding", "gzip, deflate, br") + .set("Connection", "keep-alive") + .set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); + //expect(response.header["content-type"]).toContain("application/json"); //(content not found) + expect(response.statusCode).toBe(204); + }); + + test("TC39 Verify API Response Compression (Accept-Encoding)", async () => { + }); + + test("TC41 Verify API Response Not Compressed (Other Encoding)", async () => { + }); + + test("TC42 Verify API Response Language (Accept-Language)", async () => { + }); + + test("TC43 Verify API Response Locale", async () => { + }); + + test("TC44 Verify API Response Timezone (Accept-Timezone)", async () => { + }); +}); +