From 5a416adca96a0045f0eb3f7102640d8b43f739f2 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sat, 25 Sep 2021 17:00:52 +0300 Subject: [PATCH] Covered publisher-factory with tests --- test/publisher-factory.test.ts | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/publisher-factory.test.ts diff --git a/test/publisher-factory.test.ts b/test/publisher-factory.test.ts new file mode 100644 index 0000000..7569510 --- /dev/null +++ b/test/publisher-factory.test.ts @@ -0,0 +1,44 @@ +import { describe, test, expect } from "@jest/globals"; +import PublisherFactory from "../src/publishing/publisher-factory"; +import PublisherTarget from "../src/publishing/publisher-target"; +import { getConsoleLogger } from "../src/utils/logger-utils"; + +describe("PublisherFactory.create", () => { + test("factory can create publisher for every PublisherTarget value", () => { + const factory = new PublisherFactory(); + for (const target of PublisherTarget.getValues()) { + const options = {}; + const logger = getConsoleLogger(); + const publisher = factory.create(target, options, logger); + expect(publisher.target).toStrictEqual(target); + expect((publisher).options).toStrictEqual(options); + expect((publisher).logger).toStrictEqual(logger); + } + }); + + test("every publisher has logger object", () => { + const factory = new PublisherFactory(); + for (const target of PublisherTarget.getValues()) { + const options = {}; + const publisher = factory.create(target, options); + expect(publisher.target).toStrictEqual(target); + expect((publisher).options).toStrictEqual(options); + expect((publisher).logger).toBeTruthy(); + } + }); + + test("the method throws on invalid PublisherTarget value", () => { + const factory = new PublisherFactory(); + expect(() => factory.create(-1, {})).toThrow(); + }); + + test("the method throws on invalid options", () => { + const factory = new PublisherFactory(); + const invalidOptions = [null, undefined, "", true, false, () => {}]; + for (const target of PublisherTarget.getValues()) { + for (const options of invalidOptions) { + expect(() => factory.create(target, options)).toThrow(); + } + } + }); +});