-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,90 @@ | ||
import ImageHelper from "../src/imageHelper"; | ||
import fetch from "got-cjs"; | ||
|
||
jest.mock('got-cjs'); | ||
const fetchMock = jest.mocked(fetch); | ||
|
||
describe("FetchImageFromRedditGallery", () => { | ||
test.todo("EXPECT image url to be returned"); | ||
test("EXPECT image url to be returned", async () => { | ||
fetchMock.mockResolvedValue({ | ||
body: "<html><body><img src='https://preview.redd.it/image.png' /></body></html>", | ||
errored: undefined, | ||
statusCode: 200, | ||
}); | ||
|
||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image"); | ||
|
||
expect(fetchMock).toHaveBeenCalledTimes(1); | ||
expect(fetchMock).toHaveBeenCalledWith("https://redd.it/gallery/image"); | ||
|
||
expect(result).toBe("https://preview.redd.it/image.png"); | ||
}); | ||
|
||
test("GIVEN fetch is unable to return data, EXPECT undefined returned", async () => { | ||
fetchMock.mockResolvedValue(null); | ||
|
||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image"); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test("GIVEN fetch is an error, EXPECT undefined returned", async () => { | ||
fetchMock.mockResolvedValue({ | ||
body: "<html><body><img src='https://preview.redd.it/image.png' /></body></html>", | ||
errored: "Error", | ||
statusCode: 200, | ||
}); | ||
|
||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image"); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test("GIVEN fetch is not status code of 200, EXPECT undefined returned", async () => { | ||
fetchMock.mockResolvedValue({ | ||
body: "<html><body><img src='https://preview.redd.it/image.png' /></body></html>", | ||
errored: undefined, | ||
statusCode: 500, | ||
}); | ||
|
||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image"); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test("GIVEN image tag is not found, EXPECT undefined returned", async () => { | ||
fetchMock.mockResolvedValue({ | ||
body: "<html><body></body></html>", | ||
errored: undefined, | ||
statusCode: 200, | ||
}); | ||
|
||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image"); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test("GIVEN image source attribute is not found, EXPECT undefined returned", async () => { | ||
fetchMock.mockResolvedValue({ | ||
body: "<html><body><img /></body></html>", | ||
errored: undefined, | ||
statusCode: 200, | ||
}); | ||
|
||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image"); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test.todo("GIVEN fetch is unable to return data, EXPECT undefined returned"); | ||
test("GIVEN image source attribute is not found that is a preview.redd.it url, EXPECT undefined returned", async () => { | ||
fetchMock.mockResolvedValue({ | ||
body: "<html><body><img src='main.png' /></body></html>", | ||
errored: undefined, | ||
statusCode: 200, | ||
}); | ||
|
||
test.todo("GIVEN image tag is not found, EXPECT undefined returned"); | ||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image"); | ||
|
||
test.todo("GIVEN image source attribute is not found, EXPECT undefined returned"); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters