-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.test.js
More file actions
231 lines (199 loc) · 6.15 KB
/
Copy pathindex.test.js
File metadata and controls
231 lines (199 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
'use strict'
const nock = require('nock')
const branch = require('./index')
const { expect, use } = require('chai')
const chaiAsPromised = require('chai-as-promised')
use(chaiAsPromised)
const DEMO_KEY = 'key_live_ihVdjoBF3dvzx77A00XJhnohrAdlIz9i'
const DEMO_SECRET = 'secret_live_fEGvATpzGnG2zHbta5WQKkZngxJCls0q'
describe('Branch Sdk', () => {
let client
before(() => {
client = branch({ key: DEMO_KEY, secret: DEMO_SECRET })
})
it('should throw an error if neither appId or branchKey is passed', () => {
expect(() => branch({})).to.throw('Initialize branch sdk with either appId or branchKey')
})
describe('link()', () => {
let linkData
before(() => {
linkData = {
alias: '',
stage: 'new user',
channel: 'facebook',
feature: 'dashboard',
campaign: 'content 123',
tags: [ 'tag1', 'tag2', 'tag3' ],
data: {
'custom_bool': true,
'$og_title': 'Title',
'$og_description': 'Description',
'$og_image_url': 'https://lorempixel.com/400/400'
}
}
nock('https://api.branch.io')
.post('/v1/url', {
...linkData,
branch_key: DEMO_KEY
})
.reply(200, { url: 'https://example.app.link/xwIqrtYopcvbNzXc' })
})
it('it should return a function', () => {
expect(client.link).to.be.a('Function')
})
it('it should create a deep link', () => {
return expect(client.link(linkData)).to.eventually.eql({ url: 'https://example.app.link/xwIqrtYopcvbNzXc' })
})
})
describe('bulkLinks()', () => {
let linksData
before(() => {
linksData = [
{
stage: 'new user',
channel: 'facebook',
feature: 'dashboard',
campaign: 'content 123',
tags: [ 'tag1', 'tag2', 'tag3' ],
data: {
'custom_bool': true,
'$og_title': 'Title',
'$og_description': 'Description',
'$og_image_url': 'https://lorempixel.com/400/400'
}
},
{
stage: 'new user',
channel: 'facebook',
feature: 'dashboard',
campaign: 'content 123',
tags: [ 'tag1', 'tag2', 'tag3' ],
data: {
'custom_bool': true,
'$og_title': 'Title',
'$og_description': 'Description',
'$og_image_url': 'https://lorempixel.com/400/400'
}
}
]
nock('https://api.branch.io')
.post(`/v1/url/bulk/${DEMO_KEY}`, linksData)
.reply(200, [
{ url: 'https:/example.app.link/erTweDt' },
{ url: 'https://example.app.link/xUrsD0P' }
])
})
it('should return a function', () => {
expect(client.bulkLinks).to.be.a('Function')
})
it('should create a deep link', () => {
const expectedLinks = [
{ url: 'https:/example.app.link/erTweDt' },
{ url: 'https://example.app.link/xUrsD0P' }
]
return expect(client.bulkLinks(linksData)).to.eventually.eql(expectedLinks)
})
})
describe('readLink()', () => {
let linkData
let deepLink
let response = {
campaign: 'content 123',
channel: 'facebook',
data: {
'custom_bool': true,
'$og_title': 'Title',
'~stage': 'new user',
'~channel': 'facebook',
'~creation-source': 0,
'~feature': 'dashboard',
'~campaign': 'content 123',
'~id': '579310626678425622',
'$og_description': 'Description',
'~tags': [ 'tag1', 'tag2', 'tag3' ],
'$og_image_url': 'https://lorempixel.com/400/400',
}
}
before(async () => {
linkData = {
alias: '',
stage: 'new user',
channel: 'facebook',
feature: 'dashboard',
campaign: 'content 123',
tags: [ 'tag1', 'tag2', 'tag3' ],
data: {
'custom_bool': true,
'$og_title': 'Title',
'$og_description': 'Description',
'$og_image_url': 'https://lorempixel.com/400/400'
}
}
nock('https://api.branch.io')
.post('/v1/url', {
...linkData,
branch_key: DEMO_KEY
})
.reply(200, { url: 'https://example.app.link/xwIqrtYopcvbNzXc' })
const { url } = await client.link(linkData)
deepLink = url
})
it('should throw if no link is passed as paramter', () => {
return expect(client.readLink()).to.be.rejectedWith('Parameter deepLink is required')
})
it('should return details of deep link initially created', () => {
nock('https://api.branch.io')
.get('/v1/url')
.query({ url: deepLink, branch_key: DEMO_KEY })
.reply(200, response)
return expect(client.readLink(deepLink)).to.eventually.eql(response)
})
})
describe('updateLink()', () => {
let linkData
let deepLink = 'https://example.app.link/ggxaqsx1dR'
const response = {
type: 2,
channel: 'twitter',
feature: 'marketing',
data: {
name: 'John',
'url': deepLink,
'+url': deepLink,
'~marketing': true,
user_id: '2481084010',
'~channel': 'twitter',
'~creation_source': 0,
'$one_time_use': false,
'~feature': 'marketing',
'~id': '582937710512536022'
}
}
before(async () => {
linkData = {
channel: 'twitter',
data: {
name: 'John',
user_id: 2481084010
}
}
nock('https://api.branch.io')
.put('/v1/url', {
...linkData,
branch_key: DEMO_KEY,
branch_secret: DEMO_SECRET
})
.query({ url: deepLink })
.reply(200, response)
})
it('should throw error if deepLink is not passed as parameter', () => {
return expect(client.updateLink({ data: linkData })).to.be.rejectedWith('deepLink is required')
})
it('should throw error data is not passed as parameter', () => {
return expect(client.updateLink({ deepLink })).to.be.rejectedWith('data is required')
})
it('should return updated link details', () => {
return expect(client.updateLink({ data: linkData, deepLink })).to.eventually.eql(response)
})
})
})