|
| 1 | +"use strict"; |
| 2 | +//Helpers |
| 3 | +const { |
| 4 | + getDataFromSpecificAddress, |
| 5 | +} = require("../../../../../api-integration/helpers/request/get-data-from-address"); |
| 6 | +//Const |
| 7 | +const MOCK_OBJECT_VALUE = { mock_object_key: "mock_object_value" }; |
| 8 | +const MOCK_INVALID_IP_VALUE = "192.77"; |
| 9 | +const MOCK_VALID_IP_VALUE = "8.8.8.8"; |
| 10 | +//Vars |
| 11 | +let msg; |
| 12 | +let getDataFromSpecificAddressResult; |
| 13 | + |
| 14 | +describe("- getDataFromSpecificAddress helper (Unit Test)", () => { |
| 15 | + describe("1) Check cases for arguments.", () => { |
| 16 | + msg = |
| 17 | + "Should return a string type if no arguments are passed (This function expects a single argument of string type)"; |
| 18 | + it(msg, async () => { |
| 19 | + getDataFromSpecificAddressResult = await getDataFromSpecificAddress(); |
| 20 | + await expect(typeof getDataFromSpecificAddressResult == "string").toBe( |
| 21 | + true |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + msg = |
| 26 | + "Should return a string type if not string argument is passed (This function expects a single argument of string type)"; |
| 27 | + it(msg, async () => { |
| 28 | + getDataFromSpecificAddressResult = await getDataFromSpecificAddress( |
| 29 | + MOCK_OBJECT_VALUE |
| 30 | + ); |
| 31 | + await expect(typeof getDataFromSpecificAddressResult == "string").toBe( |
| 32 | + true |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + msg = |
| 37 | + "Should return a string type if an invalid ip is passed (This function expects a single argument of string type)"; |
| 38 | + it(msg, async () => { |
| 39 | + getDataFromSpecificAddressResult = await getDataFromSpecificAddress( |
| 40 | + MOCK_INVALID_IP_VALUE |
| 41 | + ); |
| 42 | + await expect(typeof getDataFromSpecificAddressResult == "string").toBe( |
| 43 | + true |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + msg = |
| 48 | + "Should return a string type if a valid ip is passed (This function expects a single argument of string type)"; |
| 49 | + it(msg, async () => { |
| 50 | + getDataFromSpecificAddressResult = await getDataFromSpecificAddress( |
| 51 | + MOCK_VALID_IP_VALUE |
| 52 | + ); |
| 53 | + await expect(typeof getDataFromSpecificAddressResult == "string").toBe( |
| 54 | + true |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + msg = |
| 59 | + "Should return a string type if a null value is passed (This function expects a single argument of string type)"; |
| 60 | + it(msg, async () => { |
| 61 | + getDataFromSpecificAddressResult = await getDataFromSpecificAddress(null); |
| 62 | + await expect(typeof getDataFromSpecificAddressResult == "string").toBe( |
| 63 | + true |
| 64 | + ); |
| 65 | + }); |
| 66 | + |
| 67 | + msg = |
| 68 | + "Should return a string type if an undefined value is passed (This function expects a single argument of string type)"; |
| 69 | + it(msg, async () => { |
| 70 | + getDataFromSpecificAddressResult = await getDataFromSpecificAddress( |
| 71 | + undefined |
| 72 | + ); |
| 73 | + await expect(typeof getDataFromSpecificAddressResult == "string").toBe( |
| 74 | + true |
| 75 | + ); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + // describe("2) Check cases return cases.", () => { |
| 80 | + // msg = |
| 81 | + // "Should return a object type with data attribute if a valid ip is passed (This function expects a single argument of string type)"; |
| 82 | + // it(msg, async () => { |
| 83 | + // getDataFromSpecificAddressResult = await getDataFromSpecificAddress( |
| 84 | + // MOCK_VALID_IP_VALUE |
| 85 | + // ); |
| 86 | + // // await expect(typeof getDataFromSpecificAddressResult == "string").toBe( |
| 87 | + // // true |
| 88 | + // // ); |
| 89 | + // }); |
| 90 | + // }); |
| 91 | + |
| 92 | + // describe("2) Check cases for error.", () => { |
| 93 | + // msg = |
| 94 | + // "Should not return a error message and not throw an error if no argument is passed to the function."; |
| 95 | + // it(msg, async () => { |
| 96 | + // await expect(async () => await getDataFromSpecificAddress()).not.toThrow( |
| 97 | + // Error |
| 98 | + // ); |
| 99 | + // }); |
| 100 | + |
| 101 | + // msg = |
| 102 | + // "Should not return a error message and not throw an error if a new Error() is passed to the function."; |
| 103 | + // it(msg, async () => { |
| 104 | + // await expect( |
| 105 | + // async () => await getDataFromSpecificAddress(new Error()) |
| 106 | + // ).not.toThrow(Error); |
| 107 | + // }); |
| 108 | + // }); |
| 109 | +}); |
0 commit comments