Skip to content

Commit a56e7e6

Browse files
Merge pull request #12 from andresWeitzel/bug-01-update-jest-config
bug-01-update-jest-config
2 parents ae62345 + 74d84fc commit a56e7e6

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

.env

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# App config General
32
APP_FIRST_PORT = "3200"
43
APP_SECOND_PORT = "4200"
@@ -9,10 +8,3 @@ API_GRPC_IP_ENDPOINT_ADDRESS_NAME_URL = '/api/v1/grpc-ip/'
98

109
# Whois config
1110
WHOIS_BASE_URL = "https://ipwho.is/"
12-
13-
# Mock testing
14-
MOCK_STRING_01 = ""
15-
MOCK_NUMBER_01 = 8123891273812
16-
MOCK_INVALID_IP_01 = "192.77"
17-
MOCK_VALID_IP_01 = "8.8.8.8"
18-
MOCK_OBJECT_VALUE_01 = "mock_object_value"

jest.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
2-
//For using environment variables with .env
3-
const dotenv = require("dotenv");
4-
5-
module.exports = {
6-
setupFiles: ["dotenv/config"]
7-
}
1+
//For using environment variables with .envs
2+
/** @type {import('jest').Config} */
3+
const config = {
4+
setupFilesAfterEnv: ['./src/test/mock/set-env-vars.js'],
5+
};
6+
7+
module.exports = config;

src/test/mock/set-env-vars.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Mock testing
2+
process.env.MOCK_STRING_01 = ""
3+
process.env.MOCK_NUMBER_01 = 8123891273812
4+
process.env.MOCK_INVALID_IP_01 = "192.77"
5+
process.env.MOCK_VALID_IP_01 = "8.8.8.8"
6+
process.env.MOCK_OBJECT_VALUE_01 = "mock_object_value"

src/test/unit-test/api-integration/helpers/request/get-data-from-address.test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {
44
getDataFromSpecificAddress,
55
} = require("../../../../../api-integration/helpers/request/get-data-from-address");
66
//Const
7-
const MOCK_OBJECT_KEY_01 = process.env.MOCK_OBJECT_KEY_01;
7+
const MOCK_OBJECT_KEY_01 = process.env.MOCK_OBJECT_VALUE_01;
88
const MOCK_OBJECT_01 = { mock_object_key: MOCK_OBJECT_KEY_01 };
99
const MOCK_INVALID_IP_VALUE_01 = process.env.MOCK_INVALID_IP_01;
1010
const MOCK_VALID_IP_VALUE_01 = process.env.MOCK_VALID_IP_01;
@@ -15,32 +15,32 @@ let getDataFromSpecificAddressResult;
1515
describe("- getDataFromSpecificAddress helper (Unit Test)", () => {
1616
describe("1) Check cases for arguments.", () => {
1717
msg =
18-
"Should return a object type if no arguments are passed (This function expects a single argument of string type)";
18+
"Should return a string type if no arguments are passed (This function expects a single argument of string type)";
1919
it(msg, async () => {
2020
getDataFromSpecificAddressResult = await getDataFromSpecificAddress();
21-
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
21+
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
2222
true
2323
);
2424
});
2525

2626
msg =
27-
"Should return a object type if not string argument is passed (This function expects a single argument of string type)";
27+
"Should return a string type if not string argument is passed (This function expects a single argument of string type)";
2828
it(msg, async () => {
2929
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
3030
MOCK_OBJECT_01
3131
);
32-
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
32+
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
3333
true
3434
);
3535
});
3636

3737
msg =
38-
"Should return a object type if an invalid ip is passed (This function expects a single argument of string type)";
38+
"Should return a string type if an invalid ip is passed (This function expects a single argument of string type)";
3939
it(msg, async () => {
4040
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
4141
MOCK_INVALID_IP_VALUE_01
4242
);
43-
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
43+
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
4444
true
4545
);
4646
});
@@ -51,27 +51,29 @@ describe("- getDataFromSpecificAddress helper (Unit Test)", () => {
5151
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
5252
MOCK_VALID_IP_VALUE_01
5353
);
54+
55+
console.log("SS656756565655"+getDataFromSpecificAddressResult);
5456
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
5557
true
5658
);
5759
});
5860

5961
msg =
60-
"Should return a object type if a null value is passed (This function expects a single argument of string type)";
62+
"Should return a string type if a null value is passed (This function expects a single argument of string type)";
6163
it(msg, async () => {
6264
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(null);
63-
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
65+
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
6466
true
6567
);
6668
});
6769

6870
msg =
69-
"Should return a object type if an undefined value is passed (This function expects a single argument of string type)";
71+
"Should return a string type if an undefined value is passed (This function expects a single argument of string type)";
7072
it(msg, async () => {
7173
getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
7274
undefined
7375
);
74-
await expect(typeof getDataFromSpecificAddressResult == "object").toBe(
76+
await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
7577
true
7678
);
7779
});

0 commit comments

Comments
 (0)