Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createTestIntegration } from '@segment/actions-core'
import Destination from '../index'
import type { Settings } from '../generated-types'
import { generateUUIDFor } from '../utility'

const testDestination = createTestIntegration(Destination)

describe('Wingify AccountID Validation', () => {
describe('testAuthentication', () => {
it('should validate authentication inputs', async () => {
const settings: Settings = {
wingifyAccountId: 654331,
region: 'US'
}
await expect(testDestination.testAuthentication(settings)).resolves.not.toThrowError()
})

it('should throw error for invalid AccountId', async () => {
const settings: Settings = {
wingifyAccountId: 65431231,
region: 'US'
}
await expect(testDestination.testAuthentication(settings)).rejects.toThrowError()
})
})
})

describe('UUID Generator', () => {
describe('method: generateFor', () => {
it('should return desired UUID for userId and accountId', () => {
expect(generateUUIDFor('Varun', 12345)).toBe('C4D95C097902569F9A2D2E87CD3201C8')
expect(generateUUIDFor('Alice', 12345)).toBe('E3B732864F315FB6974BC3EF4E2FD920')
expect(generateUUIDFor('__123__', 12345)).toBe('50A5B167FB6356A796F91D8951E480EE')
expect(generateUUIDFor('We@#dcs3232.f3', 12345)).toBe('AAB4580A6BB3525FAA31DC341752D501')
})
})
})

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
@@ -0,0 +1,273 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import Destination from '../../index'

const testDestination = createTestIntegration(Destination)

const BASE_ENDPOINT = 'https://dev.visualwebsiteoptimizer.com'
const accountId = 654331
const wingifyUuid = 'ABC123'
const SDK_KEY = 'sample-api-key'
const SANITISED_USERID = '57CC1A3D57215E67824E461010E43F53'

describe('Wingify.identifyUser Web', () => {
describe('Only required parameters', () => {
it('should send segment traits as Wingify attributes', async () => {
const event = createTestEvent({
traits: {
wingifyUuid: wingifyUuid,
textProperty: 'Hello'
}
Comment on lines +17 to +20
})
nock(BASE_ENDPOINT).post(`/events/t?en=wingify_syncVisitorProp&a=${accountId}`).reply(200, {})
const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
wingifyAccountId: accountId
}
})
const page = event.context?.page
const expectedRequest = {
d: {
visId: wingifyUuid,
event: {
props: {
$visitor: {
props: {
'segment.textProperty': 'Hello'
}
},
wingifyMeta: {
source: 'segment.cloud'
},
page,
isCustomEvent: true
},
name: 'wingify_syncVisitorProp'
},
visitor: {
props: {
'segment.textProperty': 'Hello'
}
}
}
}
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject(expectedRequest)
expect(responses[0].options.headers).toMatchInlineSnapshot(`
Headers {
Symbol(map): Object {
"user-agent": Array [
"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1",
],
"x-forwarded-for": Array [
"8.8.8.8",
],
},
}
`)
})
})

describe('All parameters', () => {
it('should send segment traits as Wingify attributes', async () => {
const event = createTestEvent({
traits: {
wingifyUuid: wingifyUuid,
textProperty: 'Hello'
},
Comment on lines +75 to +79
context: {
page: {
url: 'www.abc.com'
},
ip: '0.0.0.0',
userAgent: 'Segment'
},
timestamp: '2023-05-09T13:12:44.924Z'
})
nock(BASE_ENDPOINT).post(`/events/t?en=wingify_syncVisitorProp&a=${accountId}`).reply(200, {})
const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
wingifyAccountId: accountId
}
})
const page = event.context?.page
const expectedRequest = {
d: {
visId: wingifyUuid,
event: {
props: {
$visitor: {
props: {
'segment.textProperty': 'Hello'
}
},
wingifyMeta: {
source: 'segment.cloud'
},
page,
isCustomEvent: true
},
name: 'wingify_syncVisitorProp'
},
visitor: {
props: {
'segment.textProperty': 'Hello'
}
}
}
}
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject(expectedRequest)
expect(responses[0].options.headers).toMatchInlineSnapshot(`
Headers {
Symbol(map): Object {
"user-agent": Array [
"Segment",
],
"x-forwarded-for": Array [
"0.0.0.0",
],
},
}
`)
})
})
})

describe('Wingify.identifyUser Fullstack', () => {
describe('Only required parameters', () => {
it('should send segment traits as Wingify attributes', async () => {
const event = createTestEvent({
traits: {
wingifyUuid: wingifyUuid,
textProperty: 'Hello'
}
Comment on lines +144 to +148
})
nock(BASE_ENDPOINT).post(`/events/t?en=wingify_syncVisitorProp&a=${accountId}`).reply(200, {})
const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
wingifyAccountId: accountId,
apikey: SDK_KEY
}
})
const page = event.context?.page
const expectedRequest = {
d: {
visId: SANITISED_USERID,
event: {
props: {
$visitor: {
props: {
'segment.textProperty': 'Hello',
wingify_fs_environment: 'sample-api-key'
}
},
wingifyMeta: {
source: 'segment.cloud'
},
page,
isCustomEvent: true
},
name: 'wingify_syncVisitorProp'
},
visitor: {
props: {
'segment.textProperty': 'Hello',
wingify_fs_environment: 'sample-api-key'
}
}
}
}
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject(expectedRequest)
expect(responses[0].options.headers).toMatchInlineSnapshot(`
Headers {
Symbol(map): Object {
"user-agent": Array [
"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1",
],
"x-forwarded-for": Array [
"8.8.8.8",
],
},
}
`)
})
})

describe('All parameters', () => {
it('should send segment traits as Wingify attributes', async () => {
const event = createTestEvent({
traits: {
wingifyUuid: wingifyUuid,
textProperty: 'Hello'
},
Comment on lines +206 to +210
context: {
page: {
url: 'www.abc.com'
},
ip: '0.0.0.0',
userAgent: 'Segment'
},
timestamp: '2023-05-09T13:12:44.924Z'
})
nock(BASE_ENDPOINT).post(`/events/t?en=wingify_syncVisitorProp&a=${accountId}`).reply(200, {})
const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
wingifyAccountId: accountId,
apikey: SDK_KEY
}
})
const page = event.context?.page
const expectedRequest = {
d: {
visId: SANITISED_USERID,
event: {
props: {
$visitor: {
props: {
'segment.textProperty': 'Hello',
wingify_fs_environment: 'sample-api-key'
}
},
wingifyMeta: {
source: 'segment.cloud'
},
page,
isCustomEvent: true
},
name: 'wingify_syncVisitorProp'
},
visitor: {
props: {
'segment.textProperty': 'Hello',
wingify_fs_environment: 'sample-api-key'
}
}
}
}
expect(responses[0].status).toBe(200)
expect(responses[0].options.json).toMatchObject(expectedRequest)
expect(responses[0].options.headers).toMatchInlineSnapshot(`
Headers {
Symbol(map): Object {
"user-agent": Array [
"Segment",
],
"x-forwarded-for": Array [
"0.0.0.0",
],
},
}
`)
})
})
})

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

Loading