Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mocks): use more complete mock generators #1383

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .idea/il-est-midi.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/classes/stores/abstract-entity-store.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AbstractEntityStoreService } from './abstract-entity-store.service';
import { ServiceNameEnum } from '../../enums/service-name.enum';
import { CoreEventService } from '../../features/core/services/core-event.service';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

interface IDummy {
name: string;
}

class DummyService extends AbstractEntityStoreService<IDummy> {
public constructor(serviceName: ServiceNameEnum) {
super(serviceName, createMock<IDummy>());
super(serviceName, createHydratedMock<IDummy>());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/classes/stores/abstract-store.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AbstractStoreService } from './abstract-store.service';
import { ServiceNameEnum } from '../../enums/service-name.enum';
import { CoreEventService } from '../../features/core/services/core-event.service';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

interface IDummy {
name: string;
}

class DummyService extends AbstractStoreService<IDummy> {
public constructor(serviceName: ServiceNameEnum) {
super(serviceName, createMock<IDummy>());
super(serviceName, createHydratedMock<IDummy>());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Activity, Client, Presence, PresenceData } from 'discord.js';
import _ from 'lodash';
import * as NodeScheduleModule from 'node-schedule';
import { BehaviorSubject, noop } from 'rxjs';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

jest.mock(`../../../logger/services/chalk/chalk.service`);
jest.mock(`node-schedule`);
Expand Down Expand Up @@ -82,7 +82,7 @@ describe(`DiscordActivitySoniaService`, (): void => {

beforeEach((): void => {
service = new DiscordActivitySoniaService();
presence = createMock<Presence>();
presence = createHydratedMock<Presence>();

loggerServiceDebugSpy = jest.spyOn(loggerService, `debug`).mockImplementation();
discordClientServiceGetClientSpy = jest.spyOn(discordClientService, `isReady$`).mockReturnValue(isReady$);
Expand Down Expand Up @@ -206,7 +206,7 @@ describe(`DiscordActivitySoniaService`, (): void => {
.mockReturnValueOnce(`dummy-schedule`)
.mockReturnValueOnce(`dummy-new-schedule`);
service = new DiscordActivitySoniaService();
job = createMock<NodeScheduleModule.Job>({
job = createHydratedMock<NodeScheduleModule.Job>({
reschedule: jobRescheduleMock,
});

Expand Down Expand Up @@ -567,7 +567,7 @@ describe(`DiscordActivitySoniaService`, (): void => {

beforeEach((): void => {
service = new DiscordActivitySoniaService();
presence = createMock<Presence>({
presence = createHydratedMock<Presence>({
activities: [
{
name: DiscordActivityNameEnum.APOLLO,
Expand All @@ -577,12 +577,12 @@ describe(`DiscordActivitySoniaService`, (): void => {
],
});
setPresenceMock = jest.fn<Promise<Presence>, unknown[]>().mockRejectedValue(new Error(`setPresence: error`));
presenceActivity = createMock<IDiscordPresenceActivity>({
presenceActivity = createHydratedMock<IDiscordPresenceActivity>({
name: DiscordActivityNameEnum.APOLLO,
type: `PLAYING`,
url: `dummy-url`,
});
client = createMock<Client>({
client = createHydratedMock<Client>({
user: {
setPresence: setPresenceMock,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DiscordClientService } from '../../services/discord-client.service';
import { DiscordSoniaConfigService } from '../../users/services/config/discord-sonia-config.service';
import { Client } from 'discord.js';
import { take } from 'rxjs/operators';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

jest.mock(`../../../logger/services/chalk/chalk.service`);

Expand Down Expand Up @@ -77,7 +77,7 @@ describe(`DiscordAuthenticationService`, (): void => {
beforeEach((): void => {
service = new DiscordAuthenticationService();
discordClientServiceGetClientOnMock = jest.fn();
client = createMock<Client>({
client = createHydratedMock<Client>({
on: discordClientServiceGetClientOnMock,
});

Expand Down Expand Up @@ -111,7 +111,7 @@ describe(`DiscordAuthenticationService`, (): void => {
discordClientServiceGetClientOnMock = jest.fn((_event: string, listener: () => void): void => {
listener();
});
client = createMock<Client>({
client = createHydratedMock<Client>({
on: discordClientServiceGetClientOnMock,
});

Expand All @@ -129,7 +129,7 @@ describe(`DiscordAuthenticationService`, (): void => {

describe(`when the Discord client user is null`, (): void => {
beforeEach((): void => {
client = createMock<Client>({
client = createHydratedMock<Client>({
on: discordClientServiceGetClientOnMock,
user: null,
});
Expand All @@ -155,7 +155,7 @@ describe(`DiscordAuthenticationService`, (): void => {

beforeEach((): void => {
tag = `dummy-tag`;
client = createMock<Client>({
client = createHydratedMock<Client>({
on: discordClientServiceGetClientOnMock,
user: {
tag,
Expand Down Expand Up @@ -223,7 +223,7 @@ describe(`DiscordAuthenticationService`, (): void => {

beforeEach((): void => {
loginMock = jest.fn().mockResolvedValue(`login`);
client = createMock<Client>({
client = createHydratedMock<Client>({
login: loginMock,
});

Expand Down Expand Up @@ -278,7 +278,7 @@ describe(`DiscordAuthenticationService`, (): void => {
describe(`when the login failed`, (): void => {
beforeEach((): void => {
loginMock = jest.fn().mockRejectedValue(new Error(`error`));
client = createMock<Client>({
client = createHydratedMock<Client>({
login: loginMock,
});

Expand Down Expand Up @@ -329,7 +329,7 @@ describe(`DiscordAuthenticationService`, (): void => {
describe(`when the login was successful`, (): void => {
beforeEach((): void => {
loginMock.mockResolvedValue(``);
client = createMock<Client>({
client = createHydratedMock<Client>({
login: loginMock,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { isDiscordGuildChannelWritable } from './is-discord-guild-channel-writable';
import { CategoryChannel, GuildChannel, NewsChannel, StoreChannel, TextChannel, VoiceChannel } from 'discord.js';
import _ from 'lodash';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

describe(`isDiscordGuildChannelWritable()`, (): void => {
let guildChannel: GuildChannel;

describe(`when the given guild channel is a text channel`, (): void => {
beforeEach((): void => {
guildChannel = createMock<TextChannel>({
guildChannel = createHydratedMock<TextChannel>({
isText(): boolean {
return _.includes([`text`, `news`], guildChannel.type);
},
Expand All @@ -26,7 +26,7 @@ describe(`isDiscordGuildChannelWritable()`, (): void => {

describe(`when the given guild channel is a voice channel`, (): void => {
beforeEach((): void => {
guildChannel = createMock<VoiceChannel>({
guildChannel = createHydratedMock<VoiceChannel>({
isText(): boolean {
return _.includes([`text`, `news`], guildChannel.type);
},
Expand All @@ -44,7 +44,7 @@ describe(`isDiscordGuildChannelWritable()`, (): void => {

describe(`when the given guild channel is a category channel`, (): void => {
beforeEach((): void => {
guildChannel = createMock<CategoryChannel>({
guildChannel = createHydratedMock<CategoryChannel>({
isText(): boolean {
return _.includes([`text`, `news`], guildChannel.type);
},
Expand All @@ -62,7 +62,7 @@ describe(`isDiscordGuildChannelWritable()`, (): void => {

describe(`when the given guild channel is a news channel`, (): void => {
beforeEach((): void => {
guildChannel = createMock<NewsChannel>({
guildChannel = createHydratedMock<NewsChannel>({
isText(): boolean {
return _.includes([`text`, `news`], guildChannel.type);
},
Expand All @@ -80,7 +80,7 @@ describe(`isDiscordGuildChannelWritable()`, (): void => {

describe(`when the given guild channel is a store channel`, (): void => {
beforeEach((): void => {
guildChannel = createMock<StoreChannel>({
guildChannel = createHydratedMock<StoreChannel>({
isText(): boolean {
return _.includes([`text`, `news`], guildChannel.type);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CoreEventService } from '../../../core/services/core-event.service';
import { ILoggerLog } from '../../../logger/interfaces/logger-log';
import { LoggerService } from '../../../logger/services/logger.service';
import { DMChannel, NewsChannel, TextChannel } from 'discord.js';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

jest.mock(`../../../logger/services/chalk/chalk.service`);

Expand Down Expand Up @@ -67,7 +67,7 @@ describe(`DiscordChannelTypingService`, (): void => {
service = new DiscordChannelTypingService();

startTypingMock = jest.fn().mockRejectedValue(new Error(`startTyping error`));
channel = createMock<TextChannel>({
channel = createHydratedMock<TextChannel>({
startTyping: startTypingMock,
});
loggerServiceErrorSpy = jest.spyOn(loggerService, `error`).mockImplementation();
Expand All @@ -85,7 +85,7 @@ describe(`DiscordChannelTypingService`, (): void => {
describe(`when an error occur with Discord`, (): void => {
beforeEach((): void => {
startTypingMock.mockRejectedValue(new Error(`startTyping error`));
channel = createMock<TextChannel>({
channel = createHydratedMock<TextChannel>({
id: `dummy-channel-id`,
startTyping: startTypingMock,
});
Expand All @@ -111,7 +111,7 @@ describe(`DiscordChannelTypingService`, (): void => {
describe(`when the typing indicator was successfully shown into Discord`, (): void => {
beforeEach((): void => {
startTypingMock.mockResolvedValue(undefined);
channel = createMock<TextChannel>({
channel = createHydratedMock<TextChannel>({
id: `dummy-channel-id`,
startTyping: startTypingMock,
});
Expand All @@ -136,7 +136,7 @@ describe(`DiscordChannelTypingService`, (): void => {
service = new DiscordChannelTypingService();

stopTypingMock = jest.fn().mockImplementation();
channel = createMock<TextChannel>({
channel = createHydratedMock<TextChannel>({
stopTyping: stopTypingMock,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DISCORD_EMOTIONAL_STATE_MESSAGES } from '../constants/discord-emotional
import { DiscordSoniaEmotionalStateEnum } from '../enums/discord-sonia-emotional-state.enum';
import * as NodeScheduleModule from 'node-schedule';
import { BehaviorSubject, noop } from 'rxjs';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

jest.mock(`../../../logger/services/chalk/chalk.service`);
jest.mock(`node-schedule`);
Expand Down Expand Up @@ -203,7 +203,7 @@ describe(`DiscordSoniaEmotionalStateService`, (): void => {
.mockReturnValueOnce(`dummy-schedule`)
.mockReturnValueOnce(`dummy-new-schedule`);
service = new DiscordSoniaEmotionalStateService();
job = createMock<NodeScheduleModule.Job>({
job = createHydratedMock<NodeScheduleModule.Job>({
reschedule: jobRescheduleMock,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AbstractService } from '../../../../../classes/services/abstract.servic
import { ServiceNameEnum } from '../../../../../enums/service-name.enum';
import { GuildChannel } from 'discord.js';
import _ from 'lodash';
import { createMock } from 'ts-auto-mock';
import { createHydratedMock } from 'ts-auto-mock';

export class DiscordGuildSoniaService extends AbstractService {
private static _instance: DiscordGuildSoniaService;
Expand All @@ -26,7 +26,7 @@ export class DiscordGuildSoniaService extends AbstractService {
public sendMessageToChannel(): void {}

public getSoniaGuildChannelByName(): GuildChannel | null | undefined {
return createMock<GuildChannel>();
return createHydratedMock<GuildChannel>();
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
Loading