@@ -2,7 +2,7 @@ import { describe, it } from 'mocha'
22import { Stack , StackCollection } from '../../lib/stack/index'
33import Axios from 'axios'
44import { expect } from 'chai'
5- import { stackMock , noticeMock , systemUidMock } from './mock/objects'
5+ import { stackMock , noticeMock , systemUidMock , stackHeadersMock } from './mock/objects'
66import MockAdapter from 'axios-mock-adapter'
77
88describe ( 'Contentstack Stack test' , ( ) => {
@@ -998,6 +998,93 @@ describe('Contentstack Stack test', () => {
998998 } )
999999 . catch ( done )
10001000 } )
1001+
1002+ it ( 'Global fields initialization without uid' , done => {
1003+ const global_field = makeStack ( {
1004+ stack : {
1005+ api_key : 'stack_api_key'
1006+ }
1007+ } )
1008+ . globalField ( )
1009+ expect ( global_field . uid ) . to . be . equal ( undefined )
1010+ expect ( global_field . stackHeaders ) . to . not . equal ( undefined )
1011+ expect ( global_field . stackHeaders . api_key ) . to . be . equal ( 'stack_api_key' )
1012+ done ( )
1013+ } )
1014+
1015+ it ( 'Management token initialization without uid' , done => {
1016+ const management_token = makeStack ( {
1017+ stack : {
1018+ api_key : 'stack_api_key'
1019+ }
1020+ } )
1021+ . managementToken ( )
1022+ expect ( management_token . uid ) . to . be . equal ( undefined )
1023+ expect ( management_token . stackHeaders ) . to . not . equal ( undefined )
1024+ expect ( management_token . stackHeaders . api_key ) . to . be . equal ( 'stack_api_key' )
1025+ done ( )
1026+ } )
1027+
1028+ it ( 'Global fields initialization uid' , done => {
1029+ const global_field = makeStack ( {
1030+ stack : {
1031+ api_key : 'stack_api_key'
1032+ }
1033+ } )
1034+ . globalField ( systemUidMock . uid )
1035+ expect ( global_field . uid ) . to . be . equal ( systemUidMock . uid )
1036+ expect ( global_field . stackHeaders . api_key ) . to . be . equal ( 'stack_api_key' )
1037+ done ( )
1038+ } )
1039+
1040+ it ( 'Management token initialization uid' , done => {
1041+ const management_token = makeStack ( {
1042+ stack : {
1043+ api_key : 'stack_api_key'
1044+ }
1045+ } )
1046+ . managementToken ( systemUidMock . uid )
1047+ expect ( management_token . uid ) . to . be . equal ( systemUidMock . uid )
1048+ expect ( management_token . stackHeaders . api_key ) . to . be . equal ( 'stack_api_key' )
1049+ done ( )
1050+ } )
1051+
1052+ it ( 'should update users roles' , done => {
1053+ var mock = new MockAdapter ( Axios )
1054+ const usersRolesData = {
1055+ user_uid : [ 'role_uid_1' , 'role_uid_2' ]
1056+ }
1057+
1058+ mock . onPost ( '/stacks/users/roles' ) . reply ( 200 , {
1059+ notice : 'Roles updated successfully'
1060+ } )
1061+
1062+ makeStack ( {
1063+ stack : {
1064+ api_key : 'stack_api_key'
1065+ }
1066+ } )
1067+ . updateUsersRoles ( usersRolesData )
1068+ . then ( ( response ) => {
1069+ expect ( response . notice ) . to . be . equal ( 'Roles updated successfully' )
1070+ done ( )
1071+ } )
1072+ . catch ( done )
1073+ } )
1074+
1075+ it ( 'should fetch variants of a stack' , done => {
1076+ var mock = new MockAdapter ( Axios )
1077+ const variantsResponse = makeStack ( {
1078+ stack : {
1079+ api_key : 'stack_api_key'
1080+ }
1081+ } )
1082+ . variants ( )
1083+ expect ( variantsResponse . create ) . to . be . not . equal ( undefined )
1084+ expect ( variantsResponse . query ) . to . be . not . equal ( undefined )
1085+ expect ( variantsResponse . fetchByUIDs ) . to . be . not . equal ( undefined )
1086+ done ( )
1087+ } )
10011088} )
10021089
10031090function makeStack ( data ) {
0 commit comments