Skip to content

Commit 23e6df8

Browse files
author
Christopher Goddard
committed
Bump version, rename method, add tests
- Rename to updateUserAgentWithAppId - Bump version - Add tests for updateUserAgentWithAppId
1 parent 091e70b commit 23e6df8

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global URL */
22
import pkgJson from '../package.json'
3-
import { when, isObject, isString, debounce, addUserAgent } from './utils'
3+
import { when, isObject, isString, debounce, updateUserAgentWithAppId } from './utils'
44
import IdleState from './utils/idleState'
55
import Tracker from './tracker'
66
import NativePromise from 'native-promise-only'
@@ -558,7 +558,7 @@ export default class Client {
558558
}
559559

560560
const appId = this._metadata && this._metadata.appId
561-
options.headers = addUserAgent(options.headers, appId)
561+
options.headers = updateUserAgentWithAppId(options.headers, appId)
562562

563563
const doneEventKey = `${requestKey}.done`
564564
const failEventKey = `${requestKey}.fail`

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import pkgJson from '../package.json'
33

44
const Promise = window.Promise || NativePromise
55

6-
export function addUserAgent (headers, appId) {
6+
export function updateUserAgentWithAppId (headers, appId) {
77
const originalUserAgent = headers && headers['User-Agent'] ? headers['User-Agent'] : ''
88
const zafSdkUserAgentString = `zendesk_app_framework_sdk/sdk_version:${pkgJson.version}/app_id:${appId}`
99
const userAgent = originalUserAgent ? `${originalUserAgent} ${zafSdkUserAgentString}` : zafSdkUserAgentString

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zendesk_app_framework_sdk",
3-
"version": "2.0.37",
3+
"version": "2.0.38",
44
"main": "build/zaf_sdk.min.js",
55
"description": "The Zendesk App Framework (ZAF) SDK is a JavaScript library that simplifies cross-frame communication between iframed apps and ZAF.",
66
"homepage": "http://developer.zendesk.com",

spec/utils_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-env mocha */
22
/* global expect Promise */
33
import * as Utils from '../lib/utils'
4+
import pkgJson from '../package.json'
45

56
describe('Utils', () => {
67
let params
@@ -151,4 +152,19 @@ describe('Utils', () => {
151152
expect(Utils.isObject(['a'])).to.equal(true)
152153
})
153154
})
155+
156+
describe('.updateUserAgentWithAppId', () => {
157+
before(() => {
158+
// Mock pkgJson
159+
global.pkgJson = { version: '1.0.0' }
160+
})
161+
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)
168+
})
169+
})
154170
})

0 commit comments

Comments
 (0)