@@ -4,6 +4,7 @@ import { contentstackClient } from '../../sanity-check/utility/ContentstackClien
44import { jsonWrite } from '../../sanity-check/utility/fileOperations/readwrite'
55import axios from 'axios'
66import dotenv from 'dotenv'
7+ import * as contentstack from '../../../lib/contentstack.js'
78
89dotenv . config ( )
910var authtoken = ''
@@ -74,4 +75,66 @@ describe('Contentstack User Session api Test', () => {
7475 } )
7576 . catch ( done )
7677 } )
78+
79+ it ( 'should get host for NA region by default' , done => {
80+ const client = contentstack . client ( )
81+ const baseUrl = client . axiosInstance . defaults . baseURL
82+ expect ( baseUrl ) . to . include ( 'api.contentstack.io' , 'region NA set correctly by default' )
83+ done ( )
84+ } )
85+
86+ it ( 'should get host for NA region' , done => {
87+ const client = contentstack . client ( { region : 'NA' } )
88+ const baseUrl = client . axiosInstance . defaults . baseURL
89+ expect ( baseUrl ) . to . include ( 'api.contentstack.io' , 'region NA set correctly' )
90+ done ( )
91+ } )
92+
93+ it ( 'should get host for NA region on priority' , done => {
94+ const client = contentstack . client ( { region : 'NA' , host : 'dev11-api.csnonprod.com' } )
95+ const baseUrl = client . axiosInstance . defaults . baseURL
96+ expect ( baseUrl ) . to . include ( 'api.contentstack.io' , 'region NA set correctly with priority' )
97+ done ( )
98+ } )
99+
100+ it ( 'should get custom host' , done => {
101+ const client = contentstack . client ( { host : 'dev11-api.csnonprod.com' } )
102+ const baseUrl = client . axiosInstance . defaults . baseURL
103+ expect ( baseUrl ) . to . include ( 'dev11-api.csnonprod.com' , 'custom host set correctly' )
104+ done ( )
105+ } )
106+
107+ it ( 'should get host for EU region' , done => {
108+ const client = contentstack . client ( { region : 'EU' } )
109+ const baseUrl = client . axiosInstance . defaults . baseURL
110+ expect ( baseUrl ) . to . include ( 'eu-api.contentstack.com' , 'region EU set correctly' )
111+ done ( )
112+ } )
113+
114+ it ( 'should get host for AZURE_NA region' , done => {
115+ const client = contentstack . client ( { region : 'AZURE_NA' } )
116+ const baseUrl = client . axiosInstance . defaults . baseURL
117+ expect ( baseUrl ) . to . include ( 'azure-na-api.contentstack.com' , 'region AZURE_NA set correctly' )
118+ done ( )
119+ } )
120+
121+ it ( 'should get host for GCP_NA region' , done => {
122+ const client = contentstack . client ( { region : 'GCP_NA' } )
123+ const baseUrl = client . axiosInstance . defaults . baseURL
124+ expect ( baseUrl ) . to . include ( 'gcp-na-api.contentstack.com' , 'region GCP_NA set correctly' )
125+ done ( )
126+ } )
127+
128+
129+ it ( 'should throw error for invalid region' , done => {
130+ try {
131+ contentstack . client ( { region : 'DUMMYREGION' } )
132+ done ( new Error ( 'Expected error was not thrown for invalid region' ) )
133+ } catch ( error ) {
134+ expect ( error . message ) . to . include ( 'Invalid region' , 'Error message should indicate invalid region' )
135+ done ( )
136+ }
137+ } )
138+
139+
77140} )
0 commit comments