Skip to content

Commit 231f046

Browse files
committed
fix: add test
1 parent 3149f55 commit 231f046

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

packages/builders/__tests__/components/v2/container.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ describe('Container Components', () => {
194194

195195
test('GIVEN valid method parameters THEN valid JSON is given', () => {
196196
expect(
197-
new ContainerBuilder().addComponents(new TextDisplayBuilder().setContent('test')).setSpoiler().toJSON(),
197+
new ContainerBuilder()
198+
.addComponents(new TextDisplayBuilder().setId(3).clearId().setContent('test'))
199+
.setSpoiler()
200+
.toJSON(),
198201
).toEqual({
199202
type: ComponentType.Container,
200203
components: [

packages/builders/__tests__/components/v2/mediagallery.test.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type APIMediaGalleryComponent, ComponentType } from 'discord-api-types/v10';
1+
import { type APIMediaGalleryItem, type APIMediaGalleryComponent, ComponentType } from 'discord-api-types/v10';
22
import { describe, test, expect } from 'vitest';
33
import { createComponentBuilder } from '../../../src/components/Components.js';
44
import { MediaGalleryBuilder } from '../../../src/components/v2/MediaGallery.js';
@@ -100,6 +100,22 @@ describe('Media Gallery Components', () => {
100100
expect(new MediaGalleryBuilder().addItems([item2]).setId(123).toJSON()).toEqual(galleryAttachmentData);
101101
});
102102

103+
test('GIVEN valid JSON options THEN valid JSON output is given 2', () => {
104+
const item1: APIMediaGalleryItem = {
105+
description: 'test',
106+
spoiler: false,
107+
media: { url: 'https://discord.com/logo.png' },
108+
};
109+
const item2 = {
110+
media: { url: 'attachment://file.png' },
111+
};
112+
113+
expect(new MediaGalleryBuilder().addItems(item1).toJSON()).toEqual(galleryHttpsDisplay);
114+
expect(new MediaGalleryBuilder().addItems(item2).setId(123).toJSON()).toEqual(galleryAttachmentData);
115+
expect(new MediaGalleryBuilder().addItems([item1]).toJSON()).toEqual(galleryHttpsDisplay);
116+
expect(new MediaGalleryBuilder().addItems([item2]).setId(123).toJSON()).toEqual(galleryAttachmentData);
117+
});
118+
103119
test('GIVEN valid builder callback THEN valid JSON output is given', () => {
104120
const item1 = new MediaGalleryItemBuilder()
105121
.setDescription('test')

packages/builders/src/components/Component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ export abstract class ComponentBuilder<
6363
*/
6464
public clearId() {
6565
this.data.id = undefined;
66+
return this;
6667
}
6768
}

0 commit comments

Comments
 (0)