aboutsummaryrefslogtreecommitdiff
path: root/src/util/config.test.ts
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2020-04-27 18:17:06 -0400
committerKevin J Hoerr <kjhoerr@protonmail.com>2020-04-27 18:17:06 -0400
commitfd2013a7bf4129b05080f01ef199d69b9ef9ec68 (patch)
tree8f8eae08b2884a0e066e01138aa6a104625d952f /src/util/config.test.ts
parent32db5f6e5e8b6f6d2baffbec44cc34daedd24533 (diff)
downloadao-coverage-fd2013a7bf4129b05080f01ef199d69b9ef9ec68.tar.gz
ao-coverage-fd2013a7bf4129b05080f01ef199d69b9ef9ec68.tar.bz2
ao-coverage-fd2013a7bf4129b05080f01ef199d69b9ef9ec68.zip
Refactor startup to passthrough values
Even more refactoring - however there were some small troubles using path in the nested scripts/files, so referencing them via the index should be a bit more stable. Plus, the config unit tests won't just exit because of configOrError constants strewn about the file.
Diffstat (limited to 'src/util/config.test.ts')
-rw-r--r--src/util/config.test.ts38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/util/config.test.ts b/src/util/config.test.ts
index b1e7df3..a065c47 100644
--- a/src/util/config.test.ts
+++ b/src/util/config.test.ts
@@ -179,6 +179,9 @@ describe("handleStartup", () => {
exit.mockClear();
});
+ const confStartup = (): Promise<MongoClient> =>
+ handleStartup("", "/apple", "/public", "localhost");
+
it("should pass back MongoClient", async () => {
const superClient = {} as MongoClient;
const fsAccess = jest.spyOn(fs.promises, "access").mockResolvedValue();
@@ -193,7 +196,7 @@ describe("handleStartup", () => {
(template: templates.Template) => new Promise(res => res(template))
);
- const result = await handleStartup();
+ const result = await confStartup();
expect(fsAccess).toHaveBeenCalledTimes(1);
expect(pathAbsolute).toHaveBeenCalledTimes(1);
@@ -209,16 +212,29 @@ describe("handleStartup", () => {
});
it("should exit if HOST_DIR is not read/write accessible", async () => {
+ const superClient = {} as MongoClient;
const fsAccess = jest.spyOn(fs.promises, "access").mockRejectedValue("boo");
const pathAbsolute = jest.spyOn(path, "isAbsolute").mockReturnValue(true);
const pathJoin = jest.spyOn(path, "join").mockReturnValue("path");
+ const mongoClient = jest.spyOn(MongoClient, "connect").mockImplementation(
+ () => new Promise<MongoClient>(res => res(superClient))
+ );
+ const processTemplate = jest
+ .spyOn(templates, "default")
+ .mockImplementation(
+ (template: templates.Template) => new Promise(res => res(template))
+ );
- const result = await handleStartup();
+ const result = await confStartup();
expect(fsAccess).toHaveBeenCalledTimes(1);
expect(exit).toHaveBeenCalledWith(1);
expect(pathAbsolute).not.toHaveBeenCalled();
+ expect(mongoClient).not.toHaveBeenCalled();
+ expect(processTemplate).not.toHaveBeenCalled();
expect(result).toBeUndefined();
+ processTemplate.mockRestore();
+ mongoClient.mockRestore();
pathAbsolute.mockRestore();
pathJoin.mockRestore();
fsAccess.mockRestore();
@@ -232,11 +248,21 @@ describe("handleStartup", () => {
const mongoClient = jest.spyOn(MongoClient, "connect").mockImplementation(
() => new Promise<MongoClient>(res => res(superClient))
);
+ const processTemplate = jest
+ .spyOn(templates, "default")
+ .mockImplementation(
+ (template: templates.Template) => new Promise(res => res(template))
+ );
- await handleStartup();
+ const result = await confStartup();
+ expect(fsAccess).toHaveBeenCalledTimes(1);
expect(pathAbsolute).toHaveBeenCalledTimes(1);
expect(exit).toHaveBeenCalledWith(1);
+ expect(mongoClient).not.toHaveBeenCalled();
+ expect(processTemplate).not.toHaveBeenCalled();
+ expect(result).toBeUndefined();
+ processTemplate.mockRestore();
mongoClient.mockRestore();
pathAbsolute.mockRestore();
pathJoin.mockRestore();
@@ -258,10 +284,14 @@ describe("handleStartup", () => {
(template: templates.Template) => new Promise(res => res(template))
);
- await handleStartup();
+ const result = await confStartup();
+ expect(fsAccess).toHaveBeenCalledTimes(1);
+ expect(pathAbsolute).toHaveBeenCalledTimes(1);
expect(mongoClient).toHaveBeenCalledTimes(1);
expect(exit).toHaveBeenCalledWith(1);
+ expect(processTemplate).not.toHaveBeenCalled();
+ expect(result).toBeUndefined();
processTemplate.mockRestore();
mongoClient.mockRestore();
pathAbsolute.mockRestore();