Files
discordeno/packages/utils/tests/token.spec.ts
Fleny 27c261fee2 formatter: Use semicolons (#4686)
I prefer semicolors, they also help avoiding certain pitfalls in JavaScript/TypeScript, such as the following code sample:
```js
const xyz = "test"
(something.else as string) = "another"
```
This results in a TypeError: "test" is not a function, this is because js thinks we are trying to call the string "test" as a function.
To fix this it requires a `;` somewhere before the `(`, such as `;(something ... ` which in my opinion is ugly and less clean overall.
2026-01-17 21:54:15 +01:00

27 lines
980 B
TypeScript

import { Buffer } from 'node:buffer';
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { getBotIdFromToken, removeTokenPrefix } from '../src/token.js';
describe('token.ts', () => {
describe('token function', () => {
it('Will remove token prefix when Bot is prefixed.', () => {
expect(removeTokenPrefix('Bot discordeno is best lib')).to.be.equal('discordeno is best lib');
});
it('Will remove token prefix when Bot is NOT prefixed.', () => {
expect(removeTokenPrefix('discordeno is best lib')).to.be.equal('discordeno is best lib');
});
it('Will throw when token is undefined.', () => {
expect(() => removeTokenPrefix(undefined)).to.throw();
});
});
describe('getBotIdFromToken function', () => {
it('Will get Bot Id from token', () => {
expect(getBotIdFromToken(`${Buffer.from('1033452747380494366').toString('base64')}.zawsxedcrftvgybhu`)).to.equal(1033452747380494366n);
});
});
});