Skip to content

Conversation

@izexi
Copy link
Contributor

@izexi izexi commented Oct 15, 2020

Here's a snippet of how I tested these changes
import { once } from 'events';
import { Client, GuildTemplate } from 'discord.js';
import { TEST_GUILD_ID, TOKEN } from './constants';

const client = new Client();
let createdChannel;

client.login(TOKEN);

test('Client#fetchGuildTemplate() & GuildTempalte#createGuild()', async () => {
  await once(client, 'ready');

  const guild = client.guilds.cache.get(TEST_GUILD_ID);

  const template = await guild.createTemplate('bar');
  expect(template).toBeInstanceOf(GuildTemplate);

  await guild
    .fetchTemplates()
    .then((templates) =>
      expect(templates.size === 1 && templates.has(template.code)).toBe(true)
    );

  await template
    .edit({ description: 'baz' })
    .then((t) => expect(t.description).toBe('baz'));

  const createdChannelName = 'qux';
  createdChannel = await guild.channels.create(createdChannelName);
  await template
    .sync()
    .then((t) =>
      expect(
        t.serializedGuild.channels.some(
          ({ name }) => name === createdChannelName
        )
      ).toBe(true)
    );

  await template.delete();
  await expect(
    client.fetchGuildTemplate(template.code).catch(() => null)
  ).resolves.toBe(null);
});

afterAll(() => createdChannel.delete());

Status

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@advaith1
Copy link
Contributor

docs PR has been merged

@izexi izexi force-pushed the unmerged-guild-template branch from f847ef1 to ecc36df Compare November 14, 2020 15:37
Copy link
Member

@SpaceEEC SpaceEEC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also add the error 30031 (A server can only have a single template.).
See: discord/discord-api-docs#2143 (comment)

@izexi izexi changed the title feat: add 'GuildTemplate#edit/delete/sync()' & 'Guild#createTemplate/fetchTemplates()' feat: add support for guild templates Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants