mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
refactor(rest): rename attachment to file (#7199)
This commit is contained in:
@@ -8,7 +8,7 @@ test('Unauthorized', () => {
|
||||
'PATCH',
|
||||
'https://discord.com/api/v9/guilds/:id',
|
||||
{
|
||||
attachments: undefined,
|
||||
files: undefined,
|
||||
body: undefined,
|
||||
},
|
||||
);
|
||||
@@ -19,7 +19,7 @@ test('Unauthorized', () => {
|
||||
expect(error.name).toBe('DiscordAPIError[0]');
|
||||
expect(error.status).toBe(401);
|
||||
expect(error.url).toBe('https://discord.com/api/v9/guilds/:id');
|
||||
expect(error.requestBody.attachments).toBe(undefined);
|
||||
expect(error.requestBody.files).toBe(undefined);
|
||||
expect(error.requestBody.json).toBe(undefined);
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ test('Invalid Form Body Error (error.{property}._errors.{index})', () => {
|
||||
'PATCH',
|
||||
'https://discord.com/api/v9/users/@me',
|
||||
{
|
||||
attachments: undefined,
|
||||
files: undefined,
|
||||
body: {
|
||||
username: 'a',
|
||||
},
|
||||
@@ -52,7 +52,7 @@ test('Invalid Form Body Error (error.{property}._errors.{index})', () => {
|
||||
expect(error.name).toBe('DiscordAPIError[50035]');
|
||||
expect(error.status).toBe(400);
|
||||
expect(error.url).toBe('https://discord.com/api/v9/users/@me');
|
||||
expect(error.requestBody.attachments).toBe(undefined);
|
||||
expect(error.requestBody.files).toBe(undefined);
|
||||
expect(error.requestBody.json).toStrictEqual({ username: 'a' });
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ nock(`${DefaultRestOptions.api}/v${DefaultRestOptions.version}`)
|
||||
.reply(200, (_, body) => body)
|
||||
.post('/postEcho')
|
||||
.reply(200, (_, body) => body)
|
||||
.post('/postAttachment')
|
||||
.post('/postFile')
|
||||
.times(5)
|
||||
.reply(200, (_, body) => ({
|
||||
body: body
|
||||
@@ -109,16 +109,16 @@ test('getReason encoded', async () => {
|
||||
expect(await api.get('/getReason', { reason: '😄' })).toStrictEqual({ reason: '%F0%9F%98%84' });
|
||||
});
|
||||
|
||||
test('postAttachment empty', async () => {
|
||||
expect(await api.post('/postAttachment', { attachments: [] })).toStrictEqual({
|
||||
test('postFile empty', async () => {
|
||||
expect(await api.post('/postFile', { files: [] })).toStrictEqual({
|
||||
body: '',
|
||||
});
|
||||
});
|
||||
|
||||
test('postAttachment attachment', async () => {
|
||||
test('postFile file', async () => {
|
||||
expect(
|
||||
await api.post('/postAttachment', {
|
||||
attachments: [{ fileName: 'out.txt', rawBuffer: Buffer.from('Hello') }],
|
||||
await api.post('/postFile', {
|
||||
files: [{ fileName: 'out.txt', rawBuffer: Buffer.from('Hello') }],
|
||||
}),
|
||||
).toStrictEqual({
|
||||
body: [
|
||||
@@ -130,10 +130,10 @@ test('postAttachment attachment', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('postAttachment attachment and JSON', async () => {
|
||||
test('postFile file and JSON', async () => {
|
||||
expect(
|
||||
await api.post('/postAttachment', {
|
||||
attachments: [{ fileName: 'out.txt', rawBuffer: Buffer.from('Hello') }],
|
||||
await api.post('/postFile', {
|
||||
files: [{ fileName: 'out.txt', rawBuffer: Buffer.from('Hello') }],
|
||||
body: { foo: 'bar' },
|
||||
}),
|
||||
).toStrictEqual({
|
||||
@@ -149,14 +149,14 @@ test('postAttachment attachment and JSON', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('postAttachment attachments and JSON', async () => {
|
||||
test('postFile files and JSON', async () => {
|
||||
expect(
|
||||
await api.post('/postAttachment', {
|
||||
attachments: [
|
||||
await api.post('/postFile', {
|
||||
files: [
|
||||
{ fileName: 'out.txt', rawBuffer: Buffer.from('Hello') },
|
||||
{ fileName: 'out.txt', rawBuffer: Buffer.from('Hi') },
|
||||
],
|
||||
body: { attachments: [{ id: 0, description: 'test' }] },
|
||||
body: { files: [{ id: 0, description: 'test' }] },
|
||||
}),
|
||||
).toStrictEqual({
|
||||
body: [
|
||||
@@ -170,15 +170,15 @@ test('postAttachment attachments and JSON', async () => {
|
||||
'Hi',
|
||||
'Content-Disposition: form-data; name="payload_json"',
|
||||
'',
|
||||
'{"attachments":[{"id":0,"description":"test"}]}',
|
||||
'{"files":[{"id":0,"description":"test"}]}',
|
||||
].join('\n'),
|
||||
});
|
||||
});
|
||||
|
||||
test('postAttachment sticker and JSON', async () => {
|
||||
test('postFile sticker and JSON', async () => {
|
||||
expect(
|
||||
await api.post('/postAttachment', {
|
||||
attachments: [{ key: 'file', fileName: 'sticker.png', rawBuffer: Buffer.from('Sticker') }],
|
||||
await api.post('/postFile', {
|
||||
files: [{ key: 'file', fileName: 'sticker.png', rawBuffer: Buffer.from('Sticker') }],
|
||||
body: { foo: 'bar' },
|
||||
appendToFormData: true,
|
||||
}),
|
||||
@@ -242,7 +242,7 @@ test('Request and Response Events', async () => {
|
||||
method: 'get',
|
||||
path: '/request',
|
||||
route: '/request',
|
||||
data: { attachments: undefined, body: undefined },
|
||||
data: { files: undefined, body: undefined },
|
||||
retries: 0,
|
||||
}) as APIRequest,
|
||||
);
|
||||
@@ -251,7 +251,7 @@ test('Request and Response Events', async () => {
|
||||
method: 'get',
|
||||
path: '/request',
|
||||
route: '/request',
|
||||
data: { attachments: undefined, body: undefined },
|
||||
data: { files: undefined, body: undefined },
|
||||
retries: 0,
|
||||
}) as APIRequest,
|
||||
expect.objectContaining({ status: 200, statusText: 'OK' }) as Response,
|
||||
|
||||
Reference in New Issue
Block a user