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

enhancement: added test cases in profile-module #44

Merged
merged 5 commits into from
Apr 15, 2024
Merged
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
20 changes: 14 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -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/**"


],
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
154 changes: 154 additions & 0 deletions service/test/addressType.test.ts
Original file line number Diff line number Diff line change
@@ -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: "[email protected]", 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 () => {
});
});

153 changes: 153 additions & 0 deletions service/test/department.test.ts
Original file line number Diff line number Diff line change
@@ -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: "[email protected]", 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 () => {
});
});
Loading
Loading