Files
discordeno/packages/utils/tests/token.spec.ts
Jonathan Ho 432abcd204 test(utils): add utils tests (#2737)
* test(utils): add urltobase64 test

* test(utils): add token test

* test(utils): fix missing import buffer

* test(utils): add casting test

* test(utils): add casting test

* test(utils): fix use correct function
2023-01-24 09:39:57 -06:00

27 lines
963 B
TypeScript

import { expect } from 'chai'
import { describe, it } from 'mocha'
import { Buffer } from 'node:buffer'
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)
})
})
})