@@ -159,12 +159,51 @@ describe('Utils', () => {
159159 global . pkgJson = { version : '1.0.0' }
160160 } )
161161
162- it ( 'should append the app id to the user agent' , ( ) => {
163- const headers = { 'User-Agent' : 'Mozilla/5.0' }
164- const appId = '1'
165- const updatedHeaders = Utils . updateUserAgentWithAppId ( headers , appId )
166- const expectedUserAgent = `Mozilla/5.0 zendesk_app_framework_sdk/sdk_version:${ pkgJson . version } /app_id:${ appId } `
167- expect ( updatedHeaders [ 'User-Agent' ] ) . to . equal ( expectedUserAgent )
162+ describe ( 'with a valid app id' , ( ) => {
163+ let appId
164+
165+ beforeEach ( ( ) => {
166+ appId = '1'
167+ } )
168+
169+ it ( 'should append the app id to the user agent' , ( ) => {
170+ const headers = { 'User-Agent' : 'Mozilla/5.0' }
171+ const updatedHeaders = Utils . updateUserAgentWithAppId ( headers , appId )
172+ const expectedUserAgent = `Mozilla/5.0 zendesk_app_framework_sdk/sdk_version:${ pkgJson . version } /app_id:${ appId } `
173+ expect ( updatedHeaders [ 'User-Agent' ] ) . to . equal ( expectedUserAgent )
174+ } )
175+
176+ it ( 'should handle an undefined headers object' , ( ) => {
177+ const updatedHeaders = Utils . updateUserAgentWithAppId ( undefined , appId )
178+ const expectedUserAgent = `zendesk_app_framework_sdk/sdk_version:${ pkgJson . version } /app_id:${ appId } `
179+ expect ( updatedHeaders [ 'User-Agent' ] ) . to . equal ( expectedUserAgent )
180+ } )
181+
182+ it ( 'should handle a headers object with no User-Agent' , ( ) => {
183+ const headers = { }
184+ const updatedHeaders = Utils . updateUserAgentWithAppId ( headers , appId )
185+ const expectedUserAgent = `zendesk_app_framework_sdk/sdk_version:${ pkgJson . version } /app_id:${ appId } `
186+ expect ( updatedHeaders [ 'User-Agent' ] ) . to . equal ( expectedUserAgent )
187+ } )
188+ } )
189+
190+ describe ( 'with an undefined app id' , ( ) => {
191+ it ( 'should not append the app id to the user agent' , ( ) => {
192+ const headers = { 'User-Agent' : 'Mozilla/5.0' }
193+ const updatedHeaders = Utils . updateUserAgentWithAppId ( headers )
194+ expect ( updatedHeaders [ 'User-Agent' ] ) . to . equal ( 'Mozilla/5.0' )
195+ } )
196+
197+ it ( 'should handle an undefined headers object' , ( ) => {
198+ const updatedHeaders = Utils . updateUserAgentWithAppId ( )
199+ expect ( updatedHeaders ) . to . be . undefined ( )
200+ } )
201+
202+ it ( 'should handle a headers object with no User-Agent' , ( ) => {
203+ const headers = { }
204+ const updatedHeaders = Utils . updateUserAgentWithAppId ( headers )
205+ expect ( updatedHeaders [ 'User-Agent' ] ) . to . equal ( undefined )
206+ } )
168207 } )
169208 } )
170209} )
0 commit comments