2015-10-18 15:01:55 +00:00
import {
generateGroup ,
generateUser ,
resetHabiticaDB ,
2015-11-03 14:31:20 +00:00
} from '../../../helpers/api-integration.helper' ;
2015-10-18 15:01:55 +00:00
describe ( 'GET /groups' , ( ) => {
2015-10-25 15:57:42 +00:00
const NUMBER _OF _PUBLIC _GUILDS = 3 ;
const NUMBER _OF _USERS _GUILDS = 2 ;
2015-12-29 23:34:33 +00:00
let user ;
2015-10-18 15:01:55 +00:00
2016-01-01 16:32:28 +00:00
before ( async ( ) => {
2015-10-18 15:01:55 +00:00
// Set up a world with a mixture of public and private guilds
// Invite user to a few of them
2016-01-02 01:33:23 +00:00
await resetHabiticaDB ( ) ;
2015-10-18 15:01:55 +00:00
2016-01-02 01:33:23 +00:00
user = await generateUser ( ) ;
let leader = await generateUser ( { balance : 10 } ) ;
2015-10-18 15:01:55 +00:00
2016-01-03 04:19:47 +00:00
await generateGroup ( leader , {
2016-01-02 01:33:23 +00:00
name : 'public guild - is member' ,
type : 'guild' ,
privacy : 'public' ,
members : [ leader . _id , user . _id ] ,
} ) ;
2015-10-18 15:01:55 +00:00
2016-01-03 04:19:47 +00:00
await generateGroup ( leader , {
2016-01-02 01:33:23 +00:00
name : 'public guild - is not member' ,
type : 'guild' ,
privacy : 'public' ,
} ) ;
2015-10-18 15:01:55 +00:00
2016-01-03 04:19:47 +00:00
await generateGroup ( leader , {
2016-01-02 01:33:23 +00:00
name : 'private guild - is member' ,
type : 'guild' ,
privacy : 'private' ,
members : [ leader . _id , user . _id ] ,
} ) ;
2015-10-18 15:01:55 +00:00
2016-01-03 04:19:47 +00:00
await generateGroup ( leader , {
2016-01-02 01:33:23 +00:00
name : 'private guild - is not member' ,
type : 'guild' ,
privacy : 'private' ,
} ) ;
2015-10-18 15:01:55 +00:00
2016-01-03 04:19:47 +00:00
await generateGroup ( leader , {
name : 'party - is not member' ,
2016-01-02 01:33:23 +00:00
type : 'party' ,
privacy : 'private' ,
} ) ;
2015-10-18 15:01:55 +00:00
2016-01-03 04:19:47 +00:00
await user . post ( '/groups' , {
name : 'party - is member' ,
2016-01-02 01:33:23 +00:00
type : 'party' ,
privacy : 'private' ,
2015-10-25 15:57:42 +00:00
} ) ;
2015-10-18 15:01:55 +00:00
} ) ;
context ( 'no query passed in' , ( ) => {
2015-10-25 16:21:19 +00:00
xit ( 'lists all public guilds, the tavern, user\'s party, and any private guilds that user is a part of - TODO query includes duplicates - IE, tavern is included as tavern and part of public guilds. Refactor so this is not the case' ) ;
2015-10-18 15:01:55 +00:00
} ) ;
context ( 'tavern passed in as query' , ( ) => {
2016-01-01 16:32:28 +00:00
it ( 'returns only the tavern' , async ( ) => {
2016-01-02 01:33:23 +00:00
await expect ( user . get ( '/groups' , null , { type : 'tavern' } ) )
2015-10-25 15:57:42 +00:00
. to . eventually . have . a . lengthOf ( 1 )
. and . to . have . deep . property ( '[0]' )
. and . to . have . property ( '_id' , 'habitrpg' ) ;
2015-10-18 15:01:55 +00:00
} ) ;
} ) ;
context ( 'party passed in as query' , ( ) => {
2016-01-01 16:32:28 +00:00
it ( 'returns only the user\'s party' , async ( ) => {
2016-01-02 01:33:23 +00:00
await expect ( user . get ( '/groups' , null , { type : 'party' } ) )
2015-10-25 15:57:42 +00:00
. to . eventually . have . a . lengthOf ( 1 )
. and . to . have . deep . property ( '[0]' )
. and . to . have . property ( 'leader' , user . _id ) ;
2015-10-18 15:01:55 +00:00
} ) ;
} ) ;
context ( 'public passed in as query' , ( ) => {
2016-01-01 16:32:28 +00:00
it ( 'returns all public guilds' , async ( ) => {
2016-01-02 01:33:23 +00:00
await expect ( user . get ( '/groups' , null , { type : 'public' } ) )
2015-10-25 15:57:42 +00:00
. to . eventually . have . a . lengthOf ( NUMBER _OF _PUBLIC _GUILDS ) ;
2015-10-18 15:01:55 +00:00
} ) ;
} ) ;
context ( 'guilds passed in as query' , ( ) => {
2016-01-01 16:32:28 +00:00
it ( 'returns all guilds user is a part of ' , async ( ) => {
2016-01-02 01:33:23 +00:00
await expect ( user . get ( '/groups' , null , { type : 'guilds' } ) )
2015-10-25 15:57:42 +00:00
. to . eventually . have . a . lengthOf ( NUMBER _OF _USERS _GUILDS ) ;
2015-10-18 15:01:55 +00:00
} ) ;
} ) ;
} ) ;