Files
discord.js/packages/rest/__tests__/RequestManager.test.ts
ckohen 8f4256db8a refactor(REST): remove double classing (#9722)
* refactor(REST): remove double classing

BREAKING CHANGE: `REST` and `RequestManager` have been combined, most of the properties, methods, and events from both classes can now be found on `REST`
BREAKING CHANGE: `REST#raw` has been removed in favor of `REST#queueRequest`
BREAKING CHANGE: `REST#getAgent` has been removed in favor of `REST#agent`

* chore: update for /rest changes
2023-07-25 08:40:21 +00:00

41 lines
1016 B
TypeScript

import { MockAgent, setGlobalDispatcher, type Interceptable } from 'undici';
import { beforeEach, afterEach, test, expect } from 'vitest';
import { REST } from '../src/index.js';
import { genPath } from './util.js';
const api = new REST();
let mockAgent: MockAgent;
let mockPool: Interceptable;
beforeEach(() => {
mockAgent = new MockAgent();
mockAgent.disableNetConnect();
setGlobalDispatcher(mockAgent);
mockPool = mockAgent.get('https://discord.com');
});
afterEach(async () => {
await mockAgent.close();
});
test('no token', async () => {
mockPool
.intercept({
path: genPath('/simpleGet'),
method: 'GET',
})
.reply(200, 'Well this is awkward...');
const promise = api.get('/simpleGet');
await expect(promise).rejects.toThrowError('Expected token to be set for this request, but none was present');
await expect(promise).rejects.toBeInstanceOf(Error);
});
test('negative offset', () => {
const badREST = new REST({ offset: -5_000 });
expect(badREST.options.offset).toEqual(0);
});