Skip to content

Commit

Permalink
Bump version, rename method, add tests
Browse files Browse the repository at this point in the history
- Rename to updateUserAgentWithAppId
- Bump version
- Add tests for updateUserAgentWithAppId
  • Loading branch information
token-cjg committed Nov 6, 2024
1 parent 091e70b commit 23e6df8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global URL */
import pkgJson from '../package.json'
import { when, isObject, isString, debounce, addUserAgent } from './utils'
import { when, isObject, isString, debounce, updateUserAgentWithAppId } from './utils'
import IdleState from './utils/idleState'
import Tracker from './tracker'
import NativePromise from 'native-promise-only'
Expand Down Expand Up @@ -558,7 +558,7 @@ export default class Client {
}

const appId = this._metadata && this._metadata.appId
options.headers = addUserAgent(options.headers, appId)
options.headers = updateUserAgentWithAppId(options.headers, appId)

const doneEventKey = `${requestKey}.done`
const failEventKey = `${requestKey}.fail`
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import pkgJson from '../package.json'

const Promise = window.Promise || NativePromise

export function addUserAgent (headers, appId) {
export function updateUserAgentWithAppId (headers, appId) {
const originalUserAgent = headers && headers['User-Agent'] ? headers['User-Agent'] : ''
const zafSdkUserAgentString = `zendesk_app_framework_sdk/sdk_version:${pkgJson.version}/app_id:${appId}`
const userAgent = originalUserAgent ? `${originalUserAgent} ${zafSdkUserAgentString}` : zafSdkUserAgentString
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zendesk_app_framework_sdk",
"version": "2.0.37",
"version": "2.0.38",
"main": "build/zaf_sdk.min.js",
"description": "The Zendesk App Framework (ZAF) SDK is a JavaScript library that simplifies cross-frame communication between iframed apps and ZAF.",
"homepage": "http://developer.zendesk.com",
Expand Down
16 changes: 16 additions & 0 deletions spec/utils_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */
/* global expect Promise */
import * as Utils from '../lib/utils'
import pkgJson from '../package.json'

describe('Utils', () => {
let params
Expand Down Expand Up @@ -151,4 +152,19 @@ describe('Utils', () => {
expect(Utils.isObject(['a'])).to.equal(true)
})
})

describe('.updateUserAgentWithAppId', () => {
before(() => {
// Mock pkgJson
global.pkgJson = { version: '1.0.0' }
})

it('should append the app id to the user agent', () => {
const headers = { 'User-Agent': 'Mozilla/5.0' }
const appId = '1'
const updatedHeaders = Utils.updateUserAgentWithAppId(headers, appId)
const expectedUserAgent = `Mozilla/5.0 zendesk_app_framework_sdk/sdk_version:${pkgJson.version}/app_id:${appId}`
expect(updatedHeaders['User-Agent']).to.equal(expectedUserAgent)
})
})
})

0 comments on commit 23e6df8

Please sign in to comment.