Remove Partial Entity
This commit is contained in:
parent
e11736dcfc
commit
f0bb455b98
@ -1,5 +1,4 @@
|
||||
import got from 'got/dist/source';
|
||||
import { PartialEntity } from '../types/ws';
|
||||
import DBWrapper from './db-wrapper';
|
||||
import { Channel } from './models/channel';
|
||||
import { Message, MessageDocument } from './models/message';
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { UpdateQuery } from 'mongoose';
|
||||
import { PermissionTypes } from '../types/permission-types';
|
||||
import { PartialEntity } from '../types/ws';
|
||||
import DBWrapper from './db-wrapper';
|
||||
|
||||
import { hasPermission, Role, RoleDocument } from './models/role';
|
||||
|
@ -1,3 +1,7 @@
|
||||
import 'mocha';
|
||||
import 'chai';
|
||||
import 'chai-as-promised';
|
||||
|
||||
import UserUpdate from '../../../src/ws/ws-events/user-update';
|
||||
import { WebSocket } from '../../../src/ws/websocket';
|
||||
import io from 'socket.io-client';
|
||||
@ -13,7 +17,7 @@ describe('user-update', () => {
|
||||
let ws: WebSocket;
|
||||
|
||||
let user: UserDocument;
|
||||
let key: string;
|
||||
let token: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
({ event, ws, user } = await Mock.defaultSetup(client, UserUpdate));
|
||||
@ -49,34 +53,31 @@ describe('user-update', () => {
|
||||
});
|
||||
|
||||
it('reorders guilds correctly, fulfilled', async () => {
|
||||
const guildIds = user.guilds.map(g => g.id);
|
||||
await expect(updateUser({ guilds: guildIds as any })).to.be.fulfilled;
|
||||
await expect(updateUser({ guildIds: user.guildIds })).to.be.fulfilled;
|
||||
});
|
||||
|
||||
it('reorders guilds but adds, rejected', async () => {
|
||||
const newGuild = await Mock.guild();
|
||||
const guildIds = (user.guilds as any).concat(newGuild).map(g => g.id);
|
||||
const guildIds = user.guildIds.concat(newGuild.id);
|
||||
|
||||
await expect(updateUser({ guilds: guildIds as any })).to.be('Cannot add or remove guilds this way');
|
||||
await expect(updateUser({ guildIds })).to.be('Cannot add or remove guilds this way');
|
||||
});
|
||||
|
||||
it('reorders guilds but removes, rejected', async () => {
|
||||
await expect(updateUser({ guilds: [] })).to.be('Cannot add or remove guilds this way');
|
||||
await expect(updateUser({ guildIds: [] })).to.be('Cannot add or remove guilds this way');
|
||||
});
|
||||
|
||||
async function updateUser(options?: Partial<UserTypes.Self>) {
|
||||
return event.invoke(ws, client, {
|
||||
key,
|
||||
partialUser: {
|
||||
avatarURL: 'https://example.com',
|
||||
username: 'mock-user',
|
||||
...options,
|
||||
},
|
||||
token,
|
||||
avatarURL: 'https://example.com',
|
||||
username: 'mock-user',
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
async function regenToken(id = user.id) {
|
||||
key = Deps
|
||||
token = Deps
|
||||
.get<Users>(Users)
|
||||
.createToken(id, false);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import GuildMembers from '../../src/data/guild-members';
|
||||
import Channels from '../../src/data/channels';
|
||||
import { PermissionTypes } from '../../src/types/permission-types';
|
||||
import { REST } from '../../src/rest/server';
|
||||
import { PartialEntity } from '../../src/types/ws';
|
||||
|
||||
// TODO: mostly replace with data wrappers
|
||||
export class Mock {
|
||||
@ -39,7 +38,7 @@ export class Mock {
|
||||
const guildId = guild.id;
|
||||
|
||||
const [user, member, role, channel] = await Promise.all([
|
||||
User.findOne({ guildIds: { $in: guild.id } }),
|
||||
User.findOne({ guildIds: guild.id }),
|
||||
GuildMember.findOne({ $not: { _id: guild.ownerId }, guildId }),
|
||||
Role.findOne({ guildId }),
|
||||
Channel.findOne({ guildId }),
|
||||
@ -102,22 +101,18 @@ export class Mock {
|
||||
}
|
||||
|
||||
public static async self(guildIds: string[] = []) {
|
||||
return await this.user(guildIds) as SelfUserDocument;
|
||||
return await this.user(guildIds) as any as SelfUserDocument;
|
||||
}
|
||||
|
||||
public static async bot(guildIds: string[] = []): Promise<SelfUserDocument> {
|
||||
return await User.create({
|
||||
_id: generateSnowflake(),
|
||||
avatarURL: 'a',
|
||||
bot: true,
|
||||
badges: [],
|
||||
friendIds: [],
|
||||
friendRequestIds: [],
|
||||
email: `${generateSnowflake()}@gmail.com`,
|
||||
guildIds,
|
||||
status: 'ONLINE',
|
||||
discriminator: 1,
|
||||
username: `mock-bot-${generateSnowflake()}`,
|
||||
} as any) as SelfUserDocument;
|
||||
} as any) as any as SelfUserDocument;
|
||||
}
|
||||
|
||||
public static guildMember(user: SelfUserDocument, guild: GuildDocument): Promise<GuildMemberDocument> {
|
||||
|
@ -27,7 +27,6 @@ use(should);
|
||||
execSync(`kill -9 $(lsof -i :${process.env.PORT} | tail -n 1 | cut -d ' ' -f5) 2>> /dev/null`);
|
||||
} catch {}
|
||||
|
||||
// disabled due to impracticality
|
||||
// await import('./integration/routes/auth-routes.tests');
|
||||
// await import('./integration/routes/invites-routes.tests');
|
||||
// await import('./integration/routes/guilds-routes.tests');
|
||||
|
9
types/ws.d.ts
vendored
9
types/ws.d.ts
vendored
@ -341,13 +341,4 @@ declare namespace WS {
|
||||
partialUser: Partial<UserTypes.Self>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated In process of being replaced with Partial. */
|
||||
export namespace PartialEntity {
|
||||
export type Guild = Partial<Entity.Guild>;
|
||||
export type GuildMember = Partial<Entity.GuildMember>;
|
||||
export type Message = Partial<Entity.Message>;
|
||||
export type Role = Partial<Entity.Role>;
|
||||
export type User = Partial<UserTypes.Self>;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user