2021-09-25 10:00:52 -04:00
|
|
|
import { describe, test, expect } from "@jest/globals";
|
2022-07-05 13:44:29 -04:00
|
|
|
import PublisherFactory from "../../../src/publishing/publisher-factory";
|
|
|
|
import PublisherTarget from "../../../src/publishing/publisher-target";
|
|
|
|
import { getConsoleLogger } from "../../../src/utils/logging/logger";
|
2021-09-25 10:00:52 -04:00
|
|
|
|
|
|
|
describe("PublisherFactory.create", () => {
|
|
|
|
test("factory can create publisher for every PublisherTarget value", () => {
|
|
|
|
const factory = new PublisherFactory();
|
|
|
|
for (const target of PublisherTarget.getValues()) {
|
|
|
|
const logger = getConsoleLogger();
|
2021-09-30 10:01:53 -04:00
|
|
|
const publisher = factory.create(target, logger);
|
2021-09-25 10:00:52 -04:00
|
|
|
expect(publisher.target).toStrictEqual(target);
|
2022-07-05 13:44:29 -04:00
|
|
|
expect((publisher as any).logger).toStrictEqual(logger);
|
2021-09-25 10:00:52 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test("every publisher has logger object", () => {
|
|
|
|
const factory = new PublisherFactory();
|
|
|
|
for (const target of PublisherTarget.getValues()) {
|
2021-09-30 10:01:53 -04:00
|
|
|
const publisher = factory.create(target);
|
2021-09-25 10:00:52 -04:00
|
|
|
expect(publisher.target).toStrictEqual(target);
|
2022-07-05 13:44:29 -04:00
|
|
|
expect((publisher as any).logger).toBeTruthy();
|
2021-09-25 10:00:52 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test("the method throws on invalid PublisherTarget value", () => {
|
|
|
|
const factory = new PublisherFactory();
|
2021-09-30 10:01:53 -04:00
|
|
|
expect(() => factory.create(-1)).toThrow();
|
2021-09-25 10:00:52 -04:00
|
|
|
});
|
|
|
|
});
|