Skip to content

Commit

Permalink
feat(lookup): add notes field to lookup results (#542)
Browse files Browse the repository at this point in the history
Adds the Notes field to lookup 
marginal color enhancements
no results message
  • Loading branch information
ssilve1989 authored Nov 10, 2024
1 parent dcd2511 commit 34ee1a9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Empty file added .gitattributes
Empty file.
29 changes: 28 additions & 1 deletion src/lookup/lookup.command-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type DeepMocked, createMock } from '@golevelup/ts-vitest';
import { Test } from '@nestjs/testing';
import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import { ChatInputCommandInteraction, Colors, EmbedBuilder } from 'discord.js';
import { Encounter } from '../encounters/encounters.consts.js';
import { SignupCollection } from '../firebase/collections/signup.collection.js';
import type { SignupDocument } from '../firebase/models/signup.model.js';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('LookupCommandHandler', () => {
world: 'jenova',
encounter: Encounter.DSR,
availability: 'Monday, Wednesday, Friday',
notes: 'Test notes',
} as SignupDocument,
];

Expand All @@ -60,6 +61,7 @@ describe('LookupCommandHandler', () => {
embeds: [
EmbedBuilder.from({
title: 'Lookup Results',
color: Colors.Green, // Green color
fields: [
{
name: 'Character',
Expand All @@ -76,9 +78,34 @@ describe('LookupCommandHandler', () => {
value: signups[0].availability,
inline: true,
},
{
name: 'Notes',
value: signups[0].notes!,
inline: false,
},
],
}),
],
});
});

it('should show no results found message when no signups are found', async () => {
const signups: SignupDocument[] = [];
signupsCollection.findAll.mockResolvedValue(signups);

const command = new LookupCommand(interaction);
await handler.execute(command);

expect(interaction.reply).toHaveBeenCalledWith({
ephemeral: true,
embeds: [
EmbedBuilder.from({
title: 'Lookup Results',
description: 'No results found!',
color: Colors.Red, // Red color
fields: [],
}),
],
});
});
});
23 changes: 20 additions & 3 deletions src/lookup/lookup.command-handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Logger } from '@nestjs/common';
import { CommandHandler, type ICommandHandler } from '@nestjs/cqrs';
import { plainToInstance } from 'class-transformer';
import { CommandInteractionOptionResolver, EmbedBuilder } from 'discord.js';
import {
Colors,
CommandInteractionOptionResolver,
EmbedBuilder,
} from 'discord.js';
import { characterField, encounterField } from '../common/components/fields.js';
import { createFields } from '../common/embed-helpers.js';
import { SignupCollection } from '../firebase/collections/signup.collection.js';
import type { SignupDocument } from '../firebase/models/signup.model.js';
import { SentryTraced } from '../observability/span.decorator.js';
Expand Down Expand Up @@ -30,18 +35,30 @@ class LookupCommandHandler implements ICommandHandler<LookupCommand> {

private createLookupEmbed(signups: SignupDocument[]) {
const fields = signups.flatMap(
({ world, character, encounter, availability }) => [
({ notes, world, character, encounter, availability }) => [
characterField(`${character} @ ${world}`),
encounterField(encounter),
{
name: 'Availability',
value: availability,
inline: true,
},
{
name: 'Notes',
value: notes,
inline: false,
},
],
);

return new EmbedBuilder().setTitle('Lookup Results').addFields(fields);
const description = signups.length === 0 ? 'No results found!' : null;
const color = description ? Colors.Red : Colors.Green;

return new EmbedBuilder()
.setTitle('Lookup Results')
.setDescription(description)
.setColor(color)
.addFields(createFields(fields));
}

private getLookupRequest(
Expand Down

0 comments on commit 34ee1a9

Please sign in to comment.