import { Collection , MockGuildMember , MockRole , MockUser } from '..' ; import { MockGuild , MockMessage } from '../types' ; export const noReply = ( msg ) => { expect . fail ( `Received unexpected reply ${ JSON . stringify ( msg ) }` ) ; } ; export const noSend = ( msg ) => { expect . fail ( `Received unexpected send ${ JSON . stringify ( msg ) }` ) ; } ; export const noDM = ( ) => { expect . fail ( `DM channel was unexpectedly created` ) ; } ; export function makeTestMessage ( { id = '1' , content , user , guild , channel = makeTestChannel ( ) , userRoles = new Collection < string , MockRole > ( ) , onReply , onCreateDM = noDM , } ) { return { id , content , author : user , channel , reply : async ( msg ) => { channel . responses . push ( msg ) ; return await ( onReply ? onReply ( msg ) : Promise . resolve ( ) ) ; } , ... ( guild ? { guild } : { } ) , ... ( guild ? { member : { id : user . id , user , createDM : ( ) => onCreateDM ( ) , roles : { cache : userRoles } } } : { } ) , } ; } export function makeTestChannel ( { id = '1' , type = 'text' , onSend , } = { } ) { return new MockChannel ( { id , type , onSend } ) ; } export class MockChannel { readonly responses : any [ ] = [ ] ; readonly id : string = '1' ; readonly type : string = 'text' ; readonly onSend : ( ( msg : any ) => Promise < unknown > ) | undefined ; constructor ( { id , type , onSend } ) { this . id = id ?? this . id ; this . type = type ?? this . type ; this . onSend = onSend ; } async send ( msg ) { this . responses . push ( msg ) ; return await ( this . onSend ? this . onSend ( msg ) : Promise . resolve ( ) ) ; } get lastResponse ( ) : any { if ( this . responses . length === 0 ) { return undefined ; } return this . responses [ this . responses . length - 1 ] ; } } export function makeTestGuild ( { id = '1' , roles = new Collection < string , MockRole > ( ) , } = { } ) { return { id , roles : { cache : roles , } , } ; }