Skip to content

Commit

Permalink
adding app_version field to a single Action (#1714)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-ayoub-segment authored Nov 15, 2023
1 parent 1f685ca commit 277fb8d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,56 @@ describe('CustomerIO', () => {
})
})

it('should send app_version if supplied', async () => {
const settings: Settings = {
siteId: '12345',
apiKey: 'abcde',
accountRegion: AccountRegion.US
}
const userId = 'abc123'
const deviceId = 'device_123'
const deviceType = 'ios'
const appVersion = '5.6.7'
const timestamp = dayjs.utc().toISOString()
trackService.put(`/customers/${userId}/devices`).reply(200, {}, { 'x-customerio-region': 'US' })
const event = createTestEvent({
userId,
timestamp,
context: {
device: {
token: deviceId,
type: deviceType
},
app: {
version: appVersion
}
}
})
const responses = await testDestination.testAction('createUpdateDevice', {
event,
settings,
useDefaultMappings: true
})

expect(responses.length).toBe(1)
expect(responses[0].status).toBe(200)
expect(responses[0].headers.toJSON()).toMatchObject({
'x-customerio-region': 'US',
'content-type': 'application/json'
})
expect(responses[0].data).toMatchObject({})
expect(responses[0].options.json).toMatchObject({
device: {
id: deviceId,
platform: deviceType,
last_used: dayjs.utc(timestamp).unix(),
attributes: {
app_version: appVersion
}
}
})
})

it("should not convert last_used if it's invalid", async () => {
const settings: Settings = {
siteId: '12345',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ const action: ActionDefinition<Settings, Payload> = {
'@path': '$.context.device.token'
}
},
app_version: {
label: 'App Version',
description: 'The version of the App',
type: 'string',
default: {
'@path': '$.context.app.version'
}
},
platform: {
label: 'Platform',
description: `The mobile device's platform. ("ios" or "android")`,
Expand Down Expand Up @@ -64,7 +72,8 @@ const action: ActionDefinition<Settings, Payload> = {
device: {
id: payload.device_id,
platform: payload.platform,
last_used: lastUsed
last_used: lastUsed,
...(payload.app_version ? { attributes: { app_version: payload.app_version } } : {})
}
}
})
Expand Down

0 comments on commit 277fb8d

Please sign in to comment.