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

Feature/#218 rewrite tests for database #232

Merged
merged 4 commits into from
Oct 11, 2023
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const chargePointValidation = require("../validation/charge-point-validation")(
{}
);
const chargePointValidation = require("../validation/charge-point-validation")({});
const { describe, expect, test } = require("@jest/globals");
const VALID_LONGITUDE = 120;
const VALID_LATITUDE = 20;
Expand All @@ -11,6 +9,7 @@ describe("Charge Point Validation with input:", () => {
const errors = chargePointValidation.chargePointValidation("", "", "");
expect(errors.length).toBe(3);
});

test("valid input", () => {
const errors = chargePointValidation.chargePointValidation(
"tst",
Expand All @@ -19,6 +18,7 @@ describe("Charge Point Validation with input:", () => {
);
expect(errors.length).toBe(0);
});

test("location array length 3", () => {
const location = [20, 20, 20];
const errors = chargePointValidation.chargePointValidation(
Expand All @@ -28,6 +28,7 @@ describe("Charge Point Validation with input:", () => {
);
expect(errors.length).toBe(1);
});

test("price null", () => {
const errors = chargePointValidation.chargePointValidation(
"tst",
Expand All @@ -36,6 +37,7 @@ describe("Charge Point Validation with input:", () => {
);
expect(errors.length).toBe(1);
});

test("price undefined", () => {
const errors = chargePointValidation.chargePointValidation(
"tst",
Expand All @@ -44,6 +46,7 @@ describe("Charge Point Validation with input:", () => {
);
expect(errors.length).toBe(1);
});

test("negative price", () => {
const errors = chargePointValidation.chargePointValidation(
"tst",
Expand All @@ -52,4 +55,4 @@ describe("Charge Point Validation with input:", () => {
);
expect(errors.length).toBe(1);
});
});
});
64 changes: 38 additions & 26 deletions backend-app/src/database-Interface/tests/charger-validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,62 @@ const { describe, expect, test } = require("@jest/globals");
const VALID_LONGITUDE = 120;
const VALID_LATITUDE = 20;

describe("Charger By SerialNumber Validation with input:", () => {
test("empty string", () => {
describe("Charger By SerialNumber Validation", () => {
test("should return an error when input is an empty string", () => {
const errors = chargerValidation.getChargerBySerialNumberValidation("");
expect(errors.length).toBe(1);
});

test("null", () => {
test("should return an error when input is null", () => {
const errors = chargerValidation.getChargerBySerialNumberValidation(null);
expect(errors.length).toBe(1);
});

test("undefined", () => {
test("should return an error when input is undefined", () => {
const valErrors =
chargerValidation.getChargerBySerialNumberValidation(undefined);
expect(valErrors.length).toBe(1);
});

test("int", () => {
test("should return an error when input is an integer", () => {
const errors = chargerValidation.getChargerBySerialNumberValidation(1);
expect(errors.length).toBe(1);
});

test("float", () => {
test("should return an error when input is a float", () => {
const errors = chargerValidation.getChargerBySerialNumberValidation(11.11);
expect(errors.length).toBe(1);
});

test("long string", () => {
test("should return an error when input is a long string", () => {
const errors = chargerValidation.getChargerBySerialNumberValidation(
"ashdfjasdfj;laksdjflkasjdf;lkjsalkdfjlkajdfljadhfaoiuwoejasklflha;sjdsljdfasdfhjalshdfkja"
);
expect(errors.length).toBe(1);
});
});

describe("Add Charger Validation with input:", () => {
test("all undefined", () => {
describe("Add Charger Validation", () => {
test("should return errors when all inputs are undefined", () => {
const errors = chargerValidation.getAddChargerValidation(
undefined,
undefined,
undefined
);
expect(errors.length).toBe(3);
});
test("all null", () => {

test("should return errors when all inputs are null", () => {
const errors = chargerValidation.getAddChargerValidation(null, null, null);
expect(errors.length).toBe(3);
});
test("all empty string", () => {

test("should return errors when all inputs are empty strings", () => {
const errors = chargerValidation.getAddChargerValidation("", "", "");
expect(errors.length).toBe(3);
});
test("location as array of string", () => {

test("should return errors when location is an array of strings", () => {
const location = ["123", "213"];
const errors = chargerValidation.getAddChargerValidation(
location,
Expand All @@ -64,16 +67,18 @@ describe("Add Charger Validation with input:", () => {
);
expect(errors.length).toBe(3);
});
test("valid input", () => {
const location = [80, 123];

test("should not return errors when input is valid", () => {
const location = [VALID_LATITUDE, VALID_LONGITUDE];
const errors = chargerValidation.getAddChargerValidation(
location,
"serialNumber",
1
);
expect(errors.length).toBe(0);
});
test("location as array of int and string", () => {

test("should return errors when location is an array of integers and strings", () => {
const location = [VALID_LATITUDE, "213"];
const errors = chargerValidation.getAddChargerValidation(
location,
Expand All @@ -82,7 +87,8 @@ describe("Add Charger Validation with input:", () => {
);
expect(errors.length).toBe(2);
});
test("location array of length 3", () => {

test("should return an error when location array has length 3", () => {
const location = [12, 12, 12];
const errors = chargerValidation.getAddChargerValidation(
location,
Expand All @@ -91,7 +97,8 @@ describe("Add Charger Validation with input:", () => {
);
expect(errors.length).toBe(1);
});
test("location array of length 1", () => {

test("should return an error when location array has length 1", () => {
const location = [12];
const errors = chargerValidation.getAddChargerValidation(
location,
Expand All @@ -102,38 +109,43 @@ describe("Add Charger Validation with input:", () => {
});
});

describe("Update Charger Status Validation with input:", () => {
test("null", () => {
describe("Update Charger Status Validation", () => {
test("should return an error when input is null", () => {
const errors = chargerValidation.getUpdateChargerStatusValidation(null);
expect(errors.length).toBe(1);
});
test("undefined", () => {

test("should return an error when input is undefined", () => {
const errors =
chargerValidation.getUpdateChargerStatusValidation(undefined);
expect(errors.length).toBe(1);
});
test("empty string", () => {

test("should return an error when input is an empty string", () => {
const errors = chargerValidation.getUpdateChargerStatusValidation("");
expect(errors.length).toBe(1);
});
test("Available", () => {

test("should not return an error when input is 'Available'", () => {
const errors =
chargerValidation.getUpdateChargerStatusValidation("Available");
expect(errors.length).toBe(0);
});
test("Availableqweqwe", () => {

test("should return an error when input is 'Availableqweqwe'", () => {
const errors =
chargerValidation.getUpdateChargerStatusValidation("Availableqweqwe");
expect(errors.length).toBe(1);
});
test("Available qweqwe", () => {

test("should return an error when input is 'Available qweqwe'", () => {
const errors =
chargerValidation.getUpdateChargerStatusValidation("Available qweqwe");
expect(errors.length).toBe(1);
});

test("int", () => {
test("should return errors when input is an integer", () => {
const errors = chargerValidation.getUpdateChargerStatusValidation(123);
expect(errors.length).toBe(2);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ describe("updateChargerStatus", () => {
done()
})
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,5 @@ describe("Invoice date", () => {
"2022-11-11"
);
expect(errors.length).toEqual(0);
});
});
});
Loading
Loading