Skip to content

Commit

Permalink
Merge branch 'feature-config-reload' into rc
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	src/lib/index.ts
  • Loading branch information
schw4rzlicht committed Jun 17, 2020
2 parents bdd61a1 + 0c021c2 commit 3ef58a5
Show file tree
Hide file tree
Showing 14 changed files with 459 additions and 283 deletions.
10 changes: 10 additions & 0 deletions __mocks__/sacn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class Receiver {

on = jest.fn();

close = jest.fn((callback?: () => any) => {
if(callback instanceof Function) {
callback();
}
});
}
25 changes: 16 additions & 9 deletions __tests__/PermissionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ let permissionController: PermissionController;

jest.mock("sacn");

beforeEach(() => {
beforeEach(async () => {

config = loadConfig();
permissionController = new PermissionController()
.withPermissionInstance(new SACNPermission(config))
.withPermissionInstance(new CooldownPermission())
.withPermissionInstance(new ModeratorPermission())
.withPermissionInstance(new OwnerPermission())
.start();
.withPermissionInstance(new OwnerPermission());

await permissionController.start();
});

afterEach(() => {
Expand Down Expand Up @@ -120,7 +122,7 @@ test("sACN lock", async () => {
expect(sacnReceiver.on).toBeCalledTimes(3);

sacnReceiver.on.mock.calls[0][1]({
slotsData: Buffer.from(new Uint8Array(512)),
payloadAsRawArray: new Array(512).fill(0),
universe: 1
});

Expand All @@ -136,7 +138,7 @@ test("sACN lock", async () => {
});

sacnReceiver.on.mock.calls[0][1]({
slotsData: Buffer.from(new Uint8Array(512).fill(255)),
payloadAsRawArray: new Array(512).fill(255),
universe: 1
});

Expand Down Expand Up @@ -164,13 +166,14 @@ test("sACN lock status", async () => {
sACNPermissionInstance.onStatus(statusHandler);

permissionController = new PermissionController()
.withPermissionInstance(sACNPermissionInstance)
.start();
.withPermissionInstance(sACNPermissionInstance);

await permissionController.start();

await expect(statusHandler).toBeCalledWith(new SACNWaiting([1]));

let sendData = {
slotsData: Buffer.from(new Uint8Array(512)),
payloadAsRawArray: new Array(512).fill(0),
universe: 1
};

Expand All @@ -183,13 +186,17 @@ test("sACN lock status", async () => {

await expect(statusHandler).toBeCalledWith(new SACNReceiving([1]));

sACNPermissionInstance.stop();
await sACNPermissionInstance.stop();

await expect(statusHandler).toBeCalledWith(new SACNStopped());

expect.assertions(5);
});

test("sACNPermission -> getUniverses()", () => {
return expect(SACNPermission.getUniverses(config)).toMatchObject([1]);
});

function loadConfig(overrideConfigValues?: any): Config {
return new Config(_.assign({}, JSON.parse(Fs.readFileSync("config.json.sample", {encoding: "utf-8"})), overrideConfigValues));
}
11 changes: 6 additions & 5 deletions __tests__/Twitch2Ma.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test("Connection chain", async () => {
twitch2Ma.onTelnetConnected(spyOnOnTelnetConnected);
twitch2Ma.onTwitchConnected(spyOnOnTwitchConnected);

await expect(twitch2Ma.start()).resolves.toBeUndefined();
await expect(twitch2Ma.start()).resolves.toBe(false);

expect(twitch2Ma["telnet"].connect).toBeCalled();
expect(spyOnTelnetLogin).toBeCalled();
Expand Down Expand Up @@ -101,7 +101,7 @@ test("Twitch connection failed", async () => {
throw Error("Not this time!");
});

await expect(twitch2Ma.start()).rejects.toThrow(new Error("Not this time!"));
await expect(twitch2Ma.start()).rejects.toMatchObject(new Error("Not this time!"));

expect(spyOnOnTelnetConnected).toBeCalledWith(config.ma.host, config.ma.user);
expect(spyOnOnTwitchConnected).not.toBeCalled();
Expand All @@ -120,18 +120,19 @@ test("Twitch channel join failed", async () => {

let spyOnOnTelnetConnected = jest.fn();
let spyOnOnTwitchConnected = jest.fn();
let spyOnError = jest.fn();

twitch2Ma.onTelnetConnected(spyOnOnTelnetConnected);
twitch2Ma.onTwitchConnected(spyOnOnTwitchConnected);
twitch2Ma.onError(spyOnError);

twitch2Ma.onError(errorHandler);
await twitch2Ma.start();
await expect(twitch2Ma.start()).rejects.toThrow(new ChannelError());

expect(twitch2Ma["chatClient"].join).toBeCalled();
expect(errorHandler).toBeCalledWith(new ChannelError());

expect(spyOnOnTelnetConnected).toBeCalledWith(config.ma.host, config.ma.user);
expect(spyOnOnTwitchConnected).not.toBeCalled();
expect(spyOnError).not.toBeCalled();
})

test("Message handler set", async () => {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test("Event handlers attached", () => {
twitch2Ma.onGodMode = jest.fn();
twitch2Ma.onNotice = jest.fn();
twitch2Ma.onError = jest.fn();
twitch2Ma.onConfigReloaded = jest.fn();

index.attachEventHandlers(twitch2Ma);

Expand All @@ -50,6 +51,7 @@ test("Event handlers attached", () => {
expect(twitch2Ma.onGodMode).toBeCalled();
expect(twitch2Ma.onNotice).toBeCalled();
expect(twitch2Ma.onError).toBeCalled();
expect(twitch2Ma.onConfigReloaded).toBeCalled();
});

test("Load JSON config successful", () => {
Expand Down
Loading

0 comments on commit 3ef58a5

Please sign in to comment.