1- import { RECEIVE_TEAM_USERS , TEAM_MEMBER_ADD , TEAM_MEMBER_DELETE , FETCH_TEAM_USERS_START } from '../../constants/allTeamsConstants' ;
2- import { teamUsersReducer , updateObject } from '../teamsTeamMembersReducer'
3-
4- const teamUsersInitial = {
5- fetching : false ,
6- fetched : false ,
7- teamMembers : [ ] ,
8- status : 404
9- } ;
1+ import {
2+ RECEIVE_TEAM_USERS ,
3+ TEAM_MEMBER_ADD ,
4+ TEAM_MEMBER_DELETE ,
5+ FETCH_TEAM_USERS_START ,
6+ } from '../../constants/allTeamsConstants' ;
7+ import { teamUsersReducer , updateObject } from '../teamsTeamMembersReducer' ;
8+
9+ // const teamUsersInitial = {
10+ // fetching: false,
11+ // fetched: false,
12+ // teamMembers: [],
13+ // status: 404,
14+ // };
1015
1116const teamMembers = {
12- teamMembers : [ {
13- _id : '1' ,
14- firstName : 'First name' ,
15- lastName : 'Last name' ,
16- jobTitle : [ '' ] ,
17- teams : [ ] ,
18- projects : [ 'p1' , 'p2' ]
19- } ]
17+ teamMembers : [
18+ {
19+ _id : '1' ,
20+ firstName : 'First name' ,
21+ lastName : 'Last name' ,
22+ jobTitle : [ '' ] ,
23+ teams : [ ] ,
24+ projects : [ 'p1' , 'p2' ] ,
25+ } ,
26+ ] ,
2027} ;
2128
2229describe ( 'Teams Team Members Reducer' , ( ) => {
23-
24- it ( 'Should receive team users' , ( ) => {
25-
26- const expectedState = { teamMembers :{ } , fetching : false , fetched : true , status : '200' } ;
27- const action = {
28- payload : { } ,
29- type :RECEIVE_TEAM_USERS
30- } ;
31-
32- const result = teamUsersReducer ( teamMembers , action ) ;
33- expect ( result ) . toEqual ( expectedState ) ;
34-
35- } ) ;
36-
37- it ( 'Should add team member to team' , ( ) => {
38-
39- const action = {
40- member : { _id : '2' , firstName : 'First name' , lastName : 'Last name' } ,
41- type :TEAM_MEMBER_ADD
42- } ;
43-
44- const expectedResult = {
45- teamMembers :[ ...teamMembers . teamMembers , action . member ] ,
46- fetching : false ,
47- fetched : true ,
48- status : '200'
49- } ;
50-
51- const result = teamUsersReducer ( teamMembers , action ) ;
52- expect ( result ) . toEqual ( expectedResult ) ;
53-
54- } ) ;
55-
56- it ( 'Should delete member from team' , ( ) => {
57-
58- const action = {
59- member : { _id : '2' , firstName : 'First name' , lastName : 'Last name' } ,
60- type : TEAM_MEMBER_DELETE
61- } ;
62-
63- const expectedResult = {
64- teamMembers :[ ...teamMembers . teamMembers . filter ( item => item . _id !== action . member . _id ) ] ,
65- fetching : false ,
66- fetched : true ,
67- status : '200'
68- } ;
69-
70- const result = teamUsersReducer ( teamMembers , action ) ;
71- expect ( result ) . toEqual ( expectedResult ) ;
72-
73- } ) ;
74-
75- it ( 'Should fetch teams user start' , ( ) => {
76-
77- const expectedResult = updateObject ( teamMembers , { fetching : true , fetched : false } ) ;
78-
79- const result = teamUsersReducer ( teamMembers , { type : FETCH_TEAM_USERS_START } ) ;
80- expect ( result ) . toEqual ( expectedResult ) ;
81-
82- } ) ;
83-
84- it ( 'Should return initial teamMembers in default case ' , ( ) => {
85-
86- const result = teamUsersReducer ( teamMembers , { } ) ;
87- expect ( result ) . toEqual ( teamMembers ) ;
88-
89- } ) ;
90-
91- } )
30+ it ( 'Should receive team users' , ( ) => {
31+ const expectedState = { teamMembers : { } , fetching : false , fetched : true , status : '200' } ;
32+ const action = {
33+ payload : { } ,
34+ type : RECEIVE_TEAM_USERS ,
35+ } ;
36+
37+ const result = teamUsersReducer ( teamMembers , action ) ;
38+ expect ( result ) . toEqual ( expectedState ) ;
39+ } ) ;
40+
41+ it ( 'Should add team member to team' , ( ) => {
42+ const action = {
43+ member : { _id : '2' , firstName : 'First name' , lastName : 'Last name' } ,
44+ type : TEAM_MEMBER_ADD ,
45+ } ;
46+
47+ const expectedResult = {
48+ teamMembers : [ ...teamMembers . teamMembers , action . member ] ,
49+ fetching : false ,
50+ fetched : true ,
51+ status : '200' ,
52+ } ;
53+
54+ const result = teamUsersReducer ( teamMembers , action ) ;
55+ expect ( result ) . toEqual ( expectedResult ) ;
56+ } ) ;
57+
58+ it ( 'Should delete member from team' , ( ) => {
59+ const action = {
60+ member : { _id : '2' , firstName : 'First name' , lastName : 'Last name' } ,
61+ type : TEAM_MEMBER_DELETE ,
62+ } ;
63+
64+ const expectedResult = {
65+ teamMembers : [ ...teamMembers . teamMembers . filter ( item => item . _id !== action . member . _id ) ] ,
66+ fetching : false ,
67+ fetched : true ,
68+ status : '200' ,
69+ } ;
70+
71+ const result = teamUsersReducer ( teamMembers , action ) ;
72+ expect ( result ) . toEqual ( expectedResult ) ;
73+ } ) ;
74+
75+ it ( 'Should fetch teams user start' , ( ) => {
76+ const expectedResult = updateObject ( teamMembers , { fetching : true , fetched : false } ) ;
77+
78+ const result = teamUsersReducer ( teamMembers , { type : FETCH_TEAM_USERS_START } ) ;
79+ expect ( result ) . toEqual ( expectedResult ) ;
80+ } ) ;
81+
82+ it ( 'Should return initial teamMembers in default case ' , ( ) => {
83+ const result = teamUsersReducer ( teamMembers , { } ) ;
84+ expect ( result ) . toEqual ( teamMembers ) ;
85+ } ) ;
86+ } ) ;
0 commit comments