Skip to content

Commit

Permalink
feat(joke): add a special joke when asking "any question?" to sonia
Browse files Browse the repository at this point in the history
you know it or you don't
  • Loading branch information
C0ZEN committed Apr 30, 2021
1 parent ad12929 commit e412972
Show file tree
Hide file tree
Showing 11 changed files with 614 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Sonia will respond to each of your messages but within a predefined priority:
- commands (handle the commands if you follow the right syntax)
- ping (respond pong)
- hotel (respond trivago)
- any question? (respond a pizza lover joke)
- default message (when your message is very basic, Sonia will tell you that it is noon, as usual (even if it is untrue))

#### In a public text channel (also known as text)
Expand All @@ -244,6 +245,7 @@ Sonia will respond to each of your messages but within a predefined priority:
- commands (handle the commands if you follow the right syntax)
- ping (respond pong)
- hotel (respond trivago)
- any question? (respond a pizza lover joke)
- default message (when your message is very basic, Sonia will tell you that it is noon, as usual (even if it is untrue))

**Example:**
Expand Down
8 changes: 8 additions & 0 deletions src/enums/service-name.enum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ describe(`ServiceNameEnum`, (): void => {
expect(ServiceNameEnum.DISCORD_MENTION_SERVICE).toStrictEqual(`DiscordMentionService`);
});

it(`should have a member "DISCORD_MESSAGE_ANY_QUESTION_PINEAPPLE_PIZZA_SERVICE"`, (): void => {
expect.assertions(1);

expect(ServiceNameEnum.DISCORD_MESSAGE_ANY_QUESTION_PINEAPPLE_PIZZA_SERVICE).toStrictEqual(
`DiscordMessageAnyQuestionPineapplePizzaService`
);
});

it(`should have a member "DISCORD_MESSAGE_AUTHOR_SERVICE"`, (): void => {
expect.assertions(1);

Expand Down
1 change: 1 addition & 0 deletions src/enums/service-name.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum ServiceNameEnum {
DISCORD_LOGGER_SERVICE = `DiscordLoggerService`,
DISCORD_LOGGER_WARNING_SERVICE = `DiscordLoggerWarningService`,
DISCORD_MENTION_SERVICE = `DiscordMentionService`,
DISCORD_MESSAGE_ANY_QUESTION_PINEAPPLE_PIZZA_SERVICE = `DiscordMessageAnyQuestionPineapplePizzaService`,
DISCORD_MESSAGE_AUTHOR_SERVICE = `DiscordMessageAuthorService`,
DISCORD_MESSAGE_COMMAND_CLI_ERROR_SERVICE = `DiscordMessageCommandCliErrorService`,
DISCORD_MESSAGE_COMMAND_COOKIE_SERVICE = `DiscordMessageCommandCookieService`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IEmptyObject } from '../../../../types/empty-object';

export type IDiscordMessageAnyQuestionPineapplePizzaResponseMessage = IEmptyObject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,340 @@
import { DiscordMessageAnyQuestionPineapplePizzaService } from './discord-message-any-question-pineapple-pizza.service';
import { ServiceNameEnum } from '../../../../../enums/service-name.enum';
import { CoreEventService } from '../../../../core/services/core-event.service';
import { IAnyDiscordMessage } from '../../types/any-discord-message';
import { DiscordMessageContentService } from '../helpers/discord-message-content.service';
import { createMock } from 'ts-auto-mock';

describe(`DiscordMessageAnyQuestionPineapplePizzaService`, (): void => {
let service: DiscordMessageAnyQuestionPineapplePizzaService;
let coreEventService: CoreEventService;
let discordMessageContentService: DiscordMessageContentService;

beforeEach((): void => {
coreEventService = CoreEventService.getInstance();
discordMessageContentService = DiscordMessageContentService.getInstance();
});

describe(`getInstance()`, (): void => {
it(`should create a DiscordMessageAnyQuestionPineapplePizzaService service`, (): void => {
expect.assertions(1);

service = DiscordMessageAnyQuestionPineapplePizzaService.getInstance();

expect(service).toStrictEqual(expect.any(DiscordMessageAnyQuestionPineapplePizzaService));
});

it(`should return the created DiscordMessageAnyQuestionPineapplePizzaService service`, (): void => {
expect.assertions(1);

const result = DiscordMessageAnyQuestionPineapplePizzaService.getInstance();

expect(result).toStrictEqual(service);
});
});

describe(`constructor()`, (): void => {
let coreEventServiceNotifyServiceCreatedSpy: jest.SpyInstance;

beforeEach((): void => {
coreEventServiceNotifyServiceCreatedSpy = jest
.spyOn(coreEventService, `notifyServiceCreated`)
.mockImplementation();
});

it(`should notify the DiscordMessageAnyQuestionPineapplePizzaService service creation`, (): void => {
expect.assertions(2);

service = new DiscordMessageAnyQuestionPineapplePizzaService();

expect(coreEventServiceNotifyServiceCreatedSpy).toHaveBeenCalledTimes(1);
expect(coreEventServiceNotifyServiceCreatedSpy).toHaveBeenCalledWith(
ServiceNameEnum.DISCORD_MESSAGE_ANY_QUESTION_PINEAPPLE_PIZZA_SERVICE
);
});
});

describe(`hasCriteria()`, (): void => {
let message: string;

beforeEach((): void => {
service = new DiscordMessageAnyQuestionPineapplePizzaService();
});

describe(`when the given message is empty`, (): void => {
beforeEach((): void => {
message = ``;
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(false);
});
});

describe(`when the given message has no mention`, (): void => {
beforeEach((): void => {
message = `dummy message`;
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(false);
});
});

describe(`when the given message has only one mention`, (): void => {
beforeEach((): void => {
message = `<@!123>`;
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(false);
});
});

describe(`when the given message has only one mention with spaces before and after`, (): void => {
beforeEach((): void => {
message = ` <@!123> `;
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(false);
});
});

describe(`when the given message has only one mention without the any question text`, (): void => {
beforeEach((): void => {
message = `<@!123> yolo`;
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(false);
});
});

describe(`when the given message has only one mention with the any question text without space between any and question`, (): void => {
beforeEach((): void => {
message = `<@!123> anyquestion?`;
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(false);
});
});

describe(`when the given message has only one mention with the any question text`, (): void => {
beforeEach((): void => {
message = `<@!123> any question?`;
});

it(`should return true`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(true);
});
});

describe(`when the given message has only one mention with the any question text and another mention`, (): void => {
beforeEach((): void => {
message = `<@!123><@!456> any question?`;
});

it(`should return false`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(false);
});
});

describe(`when the given message has only one mention with the any question text and extra spaces after`, (): void => {
beforeEach((): void => {
message = `<@!123> any question? `;
});

it(`should return true`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(true);
});
});

describe(`when the given message has only one mention with the any question text and extra spaces inside`, (): void => {
beforeEach((): void => {
message = `<@!123> any question?`;
});

it(`should return true`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(true);
});
});

describe(`when the given message has only one mention with the any question text in uppercase`, (): void => {
beforeEach((): void => {
message = `<@!123> ANY QUESTION?`;
});

it(`should return true`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(true);
});
});

describe(`when the given message has only one mention with the any question text in uppercase and extra spaces after`, (): void => {
beforeEach((): void => {
message = `<@!123> ANY QUESTION? `;
});

it(`should return true`, (): void => {
expect.assertions(1);

const result = service.hasCriteria(message);

expect(result).toStrictEqual(true);
});
});
});

describe(`reply()`, (): void => {
let anyDiscordMessage: IAnyDiscordMessage;

let discordMessageContentServiceHasContentSpy: jest.SpyInstance;

beforeEach((): void => {
service = new DiscordMessageAnyQuestionPineapplePizzaService();
anyDiscordMessage = createMock<IAnyDiscordMessage>({
content: `dummy-content`,
});

discordMessageContentServiceHasContentSpy = jest
.spyOn(discordMessageContentService, `hasContent`)
.mockImplementation();
});

it(`should check if the given Discord message is empty`, async (): Promise<void> => {
expect.assertions(3);

await expect(service.reply(anyDiscordMessage)).rejects.toThrow(new Error(`No content`));

expect(discordMessageContentServiceHasContentSpy).toHaveBeenCalledTimes(1);
expect(discordMessageContentServiceHasContentSpy).toHaveBeenCalledWith(`dummy-content`);
});

describe(`when the given Discord message is empty`, (): void => {
beforeEach((): void => {
discordMessageContentServiceHasContentSpy.mockReturnValue(false);
});

it(`should throw an error`, async (): Promise<void> => {
expect.assertions(1);

await expect(service.reply(anyDiscordMessage)).rejects.toThrow(new Error(`No content`));
});
});

describe(`when the given Discord message is not empty`, (): void => {
beforeEach((): void => {
discordMessageContentServiceHasContentSpy.mockReturnValue(true);
});

it(`should return a Discord message response not split`, async (): Promise<void> => {
expect.assertions(1);

const result = await service.reply(anyDiscordMessage);

expect(result.options.split).toStrictEqual(false);
});

describe(`when the given Discord message contains a valid mention with ANY QUESTION?`, (): void => {
beforeEach((): void => {
anyDiscordMessage.content = `<@!123> ANY QUESTION?`;
});

it(`should return a Discord message response`, async (): Promise<void> => {
expect.assertions(1);

const result = await service.reply(anyDiscordMessage);

expect(result.response).toStrictEqual(`**[dev]** Do you like pineapple pizza?`);
});
});

describe(`when the given Discord message contains a valid mention with AnY qUeStIoN?`, (): void => {
beforeEach((): void => {
anyDiscordMessage.content = `<@!123> AnY qUeStIoN?`;
});

it(`should return a Discord message response`, async (): Promise<void> => {
expect.assertions(1);

const result = await service.reply(anyDiscordMessage);

expect(result.response).toStrictEqual(`**[dev]** Do you like pineapple pizza?`);
});
});

describe(`when the given Discord message contains a valid mention with Any question?`, (): void => {
beforeEach((): void => {
anyDiscordMessage.content = `<@!123> Any question?`;
});

it(`should return a Discord message response`, async (): Promise<void> => {
expect.assertions(1);

const result = await service.reply(anyDiscordMessage);

expect(result.response).toStrictEqual(`**[dev]** Do you like pineapple pizza?`);
});
});

describe(`when the given Discord message contains a valid mention with any question?`, (): void => {
beforeEach((): void => {
anyDiscordMessage.content = `<@!123> any question?`;
});

it(`should return a Discord message response`, async (): Promise<void> => {
expect.assertions(1);

const result = await service.reply(anyDiscordMessage);

expect(result.response).toStrictEqual(`**[dev]** Do you like pineapple pizza?`);
});
});
});
});
});
Loading

0 comments on commit e412972

Please sign in to comment.