Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Sep 17, 2024
1 parent bc17169 commit 6bdbfbc
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 127 deletions.
2 changes: 1 addition & 1 deletion test/structures/interfaces/autocompleteContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AutocompleteContext } from '../../../src/structures/interfaces/autocomp
describe('AutocompleteContext', () => {
describe('constructor', () => {
it('assigns properties properly', async () => {
const ctx = new AutocompleteContext(creator, autocompleteInteraction, noop);
const ctx = new AutocompleteContext(creator, autocompleteInteraction, noop, undefined);

expect(ctx.options).to.deep.equal({ 'sub-command': { string: 'incomplete str' } });
expect(ctx.subcommands).to.deep.equal(['sub-command']);
Expand Down
17 changes: 10 additions & 7 deletions test/structures/interfaces/commandContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,40 @@ describe('CommandContext', () => {
expect(treq.status).to.equal(200);
done();
},
false
false,
false,
false,
undefined
);

clock.tick(3000);
clock.uninstall();
});

describe('For an interaction with no options', () => {
const ctx = new CommandContext(creator, basicInteraction, noop, false);
const ctx = new CommandContext(creator, basicInteraction, noop, false, false, false, undefined);

it('does not have options in the context', () => expect(ctx.options).to.deep.equal({}));
it('does not have subcommands in the context', () => expect(ctx.subcommands).to.deep.equal([]));
});

describe('For an interaction with options', () => {
const ctx = new CommandContext(creator, optionsInteraction, noop, false);
const ctx = new CommandContext(creator, optionsInteraction, noop, false, false, false, undefined);

it('has options in the context', () => expect(ctx.options).to.deep.equal({ string: 'hi', int: 2, bool: true }));
it('does not have subcommands in the context', () => expect(ctx.subcommands).to.deep.equal([]));
});

describe('For an interaction with a sub-command', () => {
const ctx = new CommandContext(creator, subCommandInteraction, noop, false);
const ctx = new CommandContext(creator, subCommandInteraction, noop, false, false, false, undefined);

it('has an empty options object within the sub-command', () =>
expect(ctx.options).to.deep.equal({ 'sub-command': {} }));
it('has a subcommand in the context', () => expect(ctx.subcommands).to.deep.equal(['sub-command']));
});

describe('For an interaction with a sub-command group', () => {
const ctx = new CommandContext(creator, subCommandGroupInteraction, noop, false);
const ctx = new CommandContext(creator, subCommandGroupInteraction, noop, false, false, false, undefined);

it('has an empty options object within the sub-command group', () =>
expect(ctx.options).to.deep.equal({ 'sub-command-group': { 'sub-command': {} } }));
Expand All @@ -76,15 +79,15 @@ describe('CommandContext', () => {
});

describe('For an interaction with a sub-command with options', () => {
const ctx = new CommandContext(creator, subCommandOptionsInteraction, noop, false);
const ctx = new CommandContext(creator, subCommandOptionsInteraction, noop, false, false, false, undefined);

it('has options within the sub-command', () =>
expect(ctx.options).to.deep.equal({ 'sub-command': { string: 'hi', int: 2, bool: true } }));
it('has subcommands in the context', () => expect(ctx.subcommands).to.deep.equal(['sub-command']));
});

it('assigns properties properly', async () => {
const ctx = new CommandContext(creator, basicInteraction, noop, false);
const ctx = new CommandContext(creator, basicInteraction, noop, false, false, false, undefined);
await ctx.defer();

expect(ctx.users.size).to.equal(0);
Expand Down
80 changes: 49 additions & 31 deletions test/structures/interfaces/componentContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ describe('ComponentContext', () => {
this.slow(6000);
const clock = FakeTimers.install();

new ComponentContext(creator, basicMessageInteraction, async (treq) => {
expect(treq.body).to.deep.equal({
type: InteractionResponseType.DEFERRED_UPDATE_MESSAGE
});
expect(treq.status).to.equal(200);
done();
});
new ComponentContext(
creator,
basicMessageInteraction,
async (treq) => {
expect(treq.body).to.deep.equal({
type: InteractionResponseType.DEFERRED_UPDATE_MESSAGE
});
expect(treq.status).to.equal(200);
done();
},
false,
undefined
);

clock.tick(3000);
clock.uninstall();
});

it('assigns properties properly', async () => {
const ctx = new ComponentContext(creator, basicMessageInteraction, noop);
const ctx = new ComponentContext(creator, basicMessageInteraction, noop, false, undefined);
await ctx.acknowledge();

expect(ctx.message.id).to.equal(basicMessageInteraction.message.id);
Expand All @@ -48,7 +54,7 @@ describe('ComponentContext', () => {
});

it('assigns properties properly for select interactions', async () => {
const ctx = new ComponentContext(creator, selectMessageInteraction, noop);
const ctx = new ComponentContext(creator, selectMessageInteraction, noop, false, undefined);
await ctx.acknowledge();

expect(ctx.message.id).to.equal(selectMessageInteraction.message.id);
Expand All @@ -60,48 +66,60 @@ describe('ComponentContext', () => {

describe('.acknowledge()', () => {
it('sends acknowledgements', async () => {
const ctx = new ComponentContext(creator, basicMessageInteraction, async (treq) => {
expect(treq.body).to.deep.equal({
type: InteractionResponseType.DEFERRED_UPDATE_MESSAGE
});
expect(treq.status).to.equal(200);
});
const ctx = new ComponentContext(
creator,
basicMessageInteraction,
async (treq) => {
expect(treq.body).to.deep.equal({
type: InteractionResponseType.DEFERRED_UPDATE_MESSAGE
});
expect(treq.status).to.equal(200);
},
false,
undefined
);
expect(ctx.initiallyResponded).to.equal(false);
await expect(ctx.acknowledge()).to.eventually.equal(true);
expect(ctx.initiallyResponded).to.equal(true);
expect(ctx.deferred).to.equal(false);
});

it('returns false when already responded', async () => {
const ctx = new ComponentContext(creator, basicMessageInteraction, noop);
const ctx = new ComponentContext(creator, basicMessageInteraction, noop, false, undefined);
await ctx.acknowledge();
await expect(ctx.acknowledge()).to.eventually.equal(false);
});
});

describe.skip('.editParent()', () => {
it('updates original message initially', async () => {
const ctx = new ComponentContext(creator, basicMessageInteraction, async (treq) => {
expect(treq.body).to.deep.equal({
type: InteractionResponseType.UPDATE_MESSAGE,
data: {
content: 'test content',
allowed_mentions: {
parse: ['roles', 'users']
},
embeds: undefined,
components: undefined
}
});
expect(treq.status).to.equal(200);
});
const ctx = new ComponentContext(
creator,
basicMessageInteraction,
async (treq) => {
expect(treq.body).to.deep.equal({
type: InteractionResponseType.UPDATE_MESSAGE,
data: {
content: 'test content',
allowed_mentions: {
parse: ['roles', 'users']
},
embeds: undefined,
components: undefined
}
});
expect(treq.status).to.equal(200);
},
false,
undefined
);
expect(ctx.initiallyResponded).to.equal(false);
await expect(ctx.editParent('test content')).to.eventually.equal(true);
expect(ctx.initiallyResponded).to.equal(true);
});

it('edits original message after acknowledging', async () => {
const ctx = new ComponentContext(creator, basicMessageInteraction, noop);
const ctx = new ComponentContext(creator, basicMessageInteraction, noop, false, undefined);
const scope = editMessage(basicMessageInteraction.message.id, followUpMessage);

await ctx.acknowledge();
Expand Down
Loading

0 comments on commit 6bdbfbc

Please sign in to comment.