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

Added more tests, cleaned up file #26

Merged
merged 1 commit into from
Nov 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 52 additions & 52 deletions BrokenLinkChecker- Release 0.1/index.test.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
// npm run test
const nock = require("nock");
const { makeCalls, processLink, fn } = require("./index.js");

let linkArr = ["https://www.youtube.com/", "https://www.google.com/", "https://www.facebook.com"];
let invalidLinkArr = ["https://www.youtube.com/", "https://www.google.com/slkdll", "https://www.facebook.com"];
let mixedLinkArr = ["https://www.youtube.com/", "https://www.google.com/slkdll", "https://www.facebook.com"];

const fetch = require("node-fetch");
// Step 1- Pick and set up a testing framework -> Jest
// Step 2

test("Pass array of valid links to makeCalls", async () => {
const result = await makeCalls(linkArr);
expect(result).toEqual([true, true, true]);
});
test("Pass array with some invalid links to makeCalls", async () => {
const result = await makeCalls(invalidLinkArr);
expect(result).not.toEqual([true, true, true]);
});
test("Pass array with some invalid links and some valid links to makeCalls", async () => {
const result = await makeCalls(invalidLinkArr);
expect(result).toEqual([true, false, true]);
});

//For some reason, null, emptyArray, or undefined might be given
//In that case, that should return some error
test("Pass array with undefined, empty array and null to makeCalls should return empty array", async () => {
[undefined, null, []].forEach(async (test) => {
const result = await makeCalls(test);
expect(result).toEqual([]);
});
});

// step 3
test("Pass valid link (status 200) to processLink", async () => {
const host = "https://www.youtube.com";
const path = "/";
nock(host).head(path).reply(200);
const url = `${host}${path}`;
const result = await processLink(url);
expect(result).toBe(true);
});
test("Pass invalid link (status 404) to processLink", async () => {
const host = "https://www.google.com/slkdll";
const path = "/";
nock(host).head(path).reply(404);
const url = `${host}${path}`;
const result = await processLink(url);
expect(result).toBe(false);
});
// Step 4 Add Code Coverage Analysis
// npm run test
const nock = require("nock");
const { makeCalls, processLink, fn } = require("./index.js");
let linkArr = ["https://www.youtube.com/", "https://www.google.com/", "https://www.facebook.com"];
let invalidLinkArr = ["https://www.youtube.com/idj", "https://www.google.com/slkdll", "https://www.facebook.com/dse"];
let mixedLinkArr = ["https://www.youtube.com/", "https://www.google.com/slkdll", "https://www.facebook.com"];
const fetch = require("node-fetch");
// Step 1- Pick and set up a testing framework -> Jest
// Step 2
test("Pass array of valid links to makeCalls", async () => {
const result = await makeCalls(linkArr);
expect(result).toEqual([true, true, true]);
});
test("Pass array with only invalid links to makeCalls", async () => {
const result = await makeCalls(invalidLinkArr);
expect(result).not.toEqual([true, true, true]);
});
test("Pass array with some invalid links and some valid links to makeCalls", async () => {
const result = await makeCalls(mixedLinkArr);
expect(result).toEqual([true, false, true]);
});
//For some reason, null, emptyArray, or undefined might be given
//In that case, that should return some error
test("Pass array with undefined, empty array and null to makeCalls should return empty array", async () => {
[undefined, null, []].forEach(async (test) => {
const result = await makeCalls(test);
expect(result).toEqual([]);
});
});
// step 3
test("Pass valid link (status 200) to processLink", async () => {
const host = "https://www.youtube.com";
const path = "/";
nock(host).head(path).reply(200);
const url = `${host}${path}`;
const result = await processLink(url);
expect(result).toBe(true);
});
test("Pass invalid link (status 404) to processLink", async () => {
const host = "https://www.google.com/slkdll";
const path = "/";
nock(host).head(path).reply(404);
const url = `${host}${path}`;
const result = await processLink(url);
expect(result).toBe(false);
});
// Step 4 Add Code Coverage Analysis