mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
fix tests
This commit is contained in:
parent
65b36a77ff
commit
650691aead
7 changed files with 13 additions and 11 deletions
|
@ -2,9 +2,6 @@ module.exports = {
|
|||
preset: 'ts-jest/presets/default-esm',
|
||||
name: 'api',
|
||||
testEnvironment: 'miniflare',
|
||||
testEnvironmentOptions: {
|
||||
envPath: '../../.env',
|
||||
},
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.test.json',
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
"build": "yarn build:dev --minify",
|
||||
"build:dev": "esbuild --bundle --sourcemap --platform=node --format=esm --outdir=dist --out-extension:.js=.mjs ./src/index.ts",
|
||||
"lint:types": "tsc --noEmit",
|
||||
"posttest": "rm .env",
|
||||
"pretest": "cp ../../.env.example .env",
|
||||
"start": "miniflare --watch --debug",
|
||||
"test": "jest"
|
||||
},
|
||||
|
|
|
@ -22,7 +22,7 @@ beforeEach(() => {
|
|||
describe('getGuild', () => {
|
||||
it('gets a guild from discord', async () => {
|
||||
const [config] = configContext();
|
||||
const guild = {
|
||||
const guild: APIGuild = {
|
||||
id: '123',
|
||||
name: 'test',
|
||||
icon: 'test',
|
||||
|
@ -46,7 +46,7 @@ describe('getGuild', () => {
|
|||
roles: [],
|
||||
};
|
||||
|
||||
await config.kv.guilds.put('123', guild, config.retention.guild);
|
||||
await config.kv.guilds.put('guild/123', guild, config.retention.guild);
|
||||
mockDiscordFetch.mockReturnValue({ ...guild, name: 'test2' });
|
||||
|
||||
const result = await getGuild(config, '123');
|
||||
|
@ -220,7 +220,7 @@ describe('getGuildMember', () => {
|
|||
nick: 'test2',
|
||||
};
|
||||
|
||||
await config.kv.guilds.put('123:members:123', member, config.retention.guild);
|
||||
await config.kv.guilds.put('member/123/123', member, config.retention.guild);
|
||||
mockDiscordFetch.mockReturnValue({ ...member, nick: 'test' });
|
||||
|
||||
const result = await getGuildMember(config, '123', '123');
|
||||
|
|
|
@ -133,7 +133,7 @@ export const getGuildMember = async (
|
|||
overrideRetention?: number // allows for own-member to be cached as long as it's used.
|
||||
): Promise<Member | null> =>
|
||||
config.kv.guilds.cacheThrough(
|
||||
`members/${serverID}/${userID}`,
|
||||
`member/${serverID}/${userID}`,
|
||||
async () => {
|
||||
const discordMember = await discordFetch<APIMember>(
|
||||
`/guilds/${serverID}/members/${userID}`,
|
||||
|
|
|
@ -37,6 +37,9 @@ describe('GET /guilds/:id', () => {
|
|||
roles: ['role-1'],
|
||||
pending: false,
|
||||
nick: '',
|
||||
user: {
|
||||
id: 'user-1',
|
||||
},
|
||||
};
|
||||
|
||||
const guildData: GuildData = {
|
||||
|
|
|
@ -11,7 +11,7 @@ beforeEach(() => {
|
|||
mockGetGuild.mockReset();
|
||||
});
|
||||
|
||||
describe('GET /guilds/slug/:id', () => {
|
||||
describe('GET /guilds/:id/slug', () => {
|
||||
it('returns a valid slug for a given discord server', async () => {
|
||||
const guild: APIGuild = {
|
||||
id: '123',
|
||||
|
@ -31,7 +31,7 @@ describe('GET /guilds/slug/:id', () => {
|
|||
|
||||
mockGetGuild.mockReturnValue(guild);
|
||||
|
||||
const response = await makeRequest('GET', `/guilds/slug/${guild.id}`);
|
||||
const response = await makeRequest('GET', `/guilds/${guild.id}/slug`);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toEqual({
|
||||
|
|
|
@ -45,8 +45,8 @@ export type Config = {
|
|||
_raw: Environment;
|
||||
};
|
||||
|
||||
const toList = (x: string): string[] => x.split(',');
|
||||
const safeURI = (x: string) => x.replace(/\/$/, '');
|
||||
const toList = (x: string): string[] => String(x).split(',');
|
||||
const safeURI = (x: string) => String(x).replace(/\/$/, '');
|
||||
|
||||
export const parseEnvironment = (env: Environment): Config => {
|
||||
return {
|
||||
|
|
Loading…
Add table
Reference in a new issue