@@ -4,6 +4,7 @@ import { contentstackClient } from '../../sanity-check/utility/ContentstackClien
4
4
import { jsonWrite } from '../../sanity-check/utility/fileOperations/readwrite'
5
5
import axios from 'axios'
6
6
import dotenv from 'dotenv'
7
+ import * as contentstack from '../../../lib/contentstack.js'
7
8
8
9
dotenv . config ( )
9
10
var authtoken = ''
@@ -74,4 +75,63 @@ describe('Contentstack User Session api Test', () => {
74
75
} )
75
76
. catch ( done )
76
77
} )
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
+ it ( 'should throw error for invalid region' , done => {
129
+ try {
130
+ contentstack . client ( { region : 'DUMMYREGION' } )
131
+ done ( new Error ( 'Expected error was not thrown for invalid region' ) )
132
+ } catch ( error ) {
133
+ expect ( error . message ) . to . include ( 'Invalid region' , 'Error message should indicate invalid region' )
134
+ done ( )
135
+ }
136
+ } )
77
137
} )
0 commit comments