Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgolea committed Dec 2, 2021
1 parent 72c0361 commit f954934
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions apps/online-checker/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const users: User[] = new Array(10).fill(0).map(
} as User)
);
describe('AppService', () => {
const botClient = mock<ClientProxy>();
let service: AppService;
let dbService: BotDatabaseService;
let twitchClientService: TwitchClientService;
let botClient: ClientProxy;

const queue = mock<Queue>();

Expand Down Expand Up @@ -62,13 +62,14 @@ describe('AppService', () => {
.useValue(mock<TwitchClientService>())
.overrideProvider(getQueueToken('queue'))
.useValue(queue)
.overrideProvider(BOT_CONNECTION)
.useValue(botClient)
.compile();

service = testingModule.get<AppService>(AppService);
dbService = testingModule.get<BotDatabaseService>(BotDatabaseService);
twitchClientService =
testingModule.get<TwitchClientService>(TwitchClientService);
botClient = testingModule.get<ClientProxy>(BOT_CONNECTION);

await dbService.machine.create({
data: {
Expand Down Expand Up @@ -167,9 +168,7 @@ describe('AppService', () => {
.spyOn(twitchClientService, 'checkUsersStatus')
.mockImplementation(() => Promise.resolve(response));

const botHandlerClientEmitMock = jest
.spyOn(botClient, 'emit')
.mockImplementation(() => of(null));
botClient.send.mockImplementation(() => of(null));

await service.checkIfUserIsOnline();

Expand All @@ -179,17 +178,22 @@ describe('AppService', () => {

expect(queue.add).toHaveBeenCalledTimes(online.length);

expect(botHandlerClientEmitMock.mock.calls).toEqual(
expect(botClient.send.mock.calls).toEqual(
expect.arrayContaining([
...offline.map((u) => [
BotPatterns.USER_OFFLINE,
...online.map((u) => [
BotPatterns.USER_ONLINE,
{
botId: machineUUID,
channelName: u.user_login,
},
]),
...online.map((u) => [
BotPatterns.USER_ONLINE,
])
);

expect(botClient.emit.mock.calls).toEqual(
expect.arrayContaining([
...offline.map((u) => [
BotPatterns.USER_OFFLINE,
{
botId: machineUUID,
channelName: u.user_login,
Expand Down

0 comments on commit f954934

Please sign in to comment.