Skip to content

Commit 578bfde

Browse files
committed
test: modify tests
1 parent 4aa5cae commit 578bfde

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

packages/config/src/api/site_info.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ const getIntegrations = async function ({
125125

126126
const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`)
127127

128-
const url = `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}`
128+
// if accountId isn't present, use safe v1 endpoint
129+
const url = accountId
130+
? `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}`
131+
: `${baseUrl}site/${siteId}/integrations/safe`
129132

130133
try {
131134
const response = await fetch(url)

packages/config/tests/api/tests.js

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const SITE_INTEGRATIONS_RESPONSE = {
2020
response: [
2121
{
2222
slug: 'test',
23-
version: 'so-cool',
23+
version: 'so-cool-v1',
2424
has_build: true,
2525
},
2626
],
@@ -31,7 +31,7 @@ const TEAM_INSTALLATIONS_META_RESPONSE = {
3131
response: [
3232
{
3333
slug: 'test',
34-
version: 'so-cool',
34+
version: 'so-cool-v2',
3535
has_build: true,
3636
},
3737
],
@@ -42,6 +42,11 @@ const SITE_INTEGRATIONS_EMPTY_RESPONSE = {
4242
response: [],
4343
}
4444

45+
const TEAM_INSTALLATIONS_META_EMPTY_RESPONSE = {
46+
path: '/team/account1/integrations/installations/meta/test',
47+
response: [],
48+
}
49+
4550
const SITE_INFO_BUILD_SETTINGS = {
4651
path: SITE_INFO_PATH,
4752
response: {
@@ -222,7 +227,7 @@ test('Build settings are not used in CI', async (t) => {
222227
t.snapshot(normalizeOutput(output))
223228
})
224229

225-
test('Integrations are returned if feature flag is true', async (t) => {
230+
test('Integrations are returned from getSiteInfo from v1 safe API when there is not accountID', async (t) => {
226231
const { output } = await new Fixture('./fixtures/base')
227232
.withFlags({
228233
token: 'test',
@@ -235,7 +240,7 @@ test('Integrations are returned if feature flag is true', async (t) => {
235240
t.assert(config.integrations)
236241
t.assert(config.integrations.length === 1)
237242
t.assert(config.integrations[0].slug === 'test')
238-
t.assert(config.integrations[0].version === 'so-cool')
243+
t.assert(config.integrations[0].version === 'so-cool-v1')
239244
t.assert(config.integrations[0].has_build === true)
240245
})
241246

@@ -244,8 +249,9 @@ test('Integration specified in config is also returned if integration is availab
244249
.withFlags({
245250
token: 'test',
246251
siteId: 'test',
252+
accountId: 'account1',
247253
})
248-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_RESPONSE])
254+
.runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_RESPONSE])
249255

250256
const config = JSON.parse(output)
251257

@@ -262,8 +268,9 @@ test('Integration specified in config is not returned if integration is not avai
262268
.withFlags({
263269
token: 'test',
264270
siteId: 'test',
271+
accountId: 'account1',
265272
})
266-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
273+
.runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
267274

268275
const config = JSON.parse(output)
269276

@@ -278,8 +285,9 @@ test('In integration dev mode, integration specified in config is returned even
278285
token: 'test',
279286
siteId: 'test',
280287
context: 'dev',
288+
accountId: 'account1',
281289
})
282-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
290+
.runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
283291

284292
const config = JSON.parse(output)
285293

@@ -292,6 +300,25 @@ test('In integration dev mode, integration specified in config is returned even
292300
})
293301

294302
test('In integration dev mode, integration specified in config is returned even if integration is not enabled on site', async (t) => {
303+
const { output } = await new Fixture('./fixtures/dev_integration')
304+
.withFlags({
305+
token: 'test',
306+
siteId: 'test',
307+
context: 'dev',
308+
accountId: 'account1',
309+
})
310+
.runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_EMPTY_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
311+
312+
const config = JSON.parse(output)
313+
314+
t.assert(config.integrations)
315+
t.assert(config.integrations.length === 1)
316+
t.assert(config.integrations[0].slug === 'abc-integration')
317+
t.assert(config.integrations[0].has_build === false)
318+
t.assert(config.integrations[0].version === undefined)
319+
})
320+
321+
test('In integration dev mode, integration specified in config is returned even if integration is not enabled on site and accountId not present', async (t) => {
295322
const { output } = await new Fixture('./fixtures/dev_integration')
296323
.withFlags({
297324
token: 'test',
@@ -315,8 +342,9 @@ test('In integration dev mode, integration specified in config is returned and b
315342
token: 'test',
316343
siteId: 'test',
317344
context: 'dev',
345+
accountId: 'account1',
318346
})
319-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_EMPTY_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
347+
.runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_EMPTY_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
320348

321349
const config = JSON.parse(output)
322350

@@ -333,8 +361,9 @@ test('Integrations are not returned if offline', async (t) => {
333361
offline: true,
334362
siteId: 'test',
335363
mode: 'buildbot',
364+
accountId: 'account1',
336365
})
337-
.runConfigServer([SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
366+
.runConfigServer([TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
338367

339368
const config = JSON.parse(output)
340369

@@ -350,36 +379,37 @@ test('Integrations and account id are returned if feature flag is false and mode
350379
accountId: 'account1',
351380
token: 'test',
352381
})
353-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
382+
.runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
354383

355384
const config = JSON.parse(output)
356385

357386
t.assert(config.integrations)
358387
t.is(config.integrations.length, 1)
359388
t.is(config.integrations[0].slug, 'test')
360-
t.is(config.integrations[0].version, 'so-cool')
389+
t.is(config.integrations[0].version, 'so-cool-v2')
361390
t.is(config.integrations[0].has_build, true)
362391

363392
// account id is also available
364393
t.assert(config.siteInfo)
365394
t.is(config.siteInfo.account_id, 'account1')
366395
})
367396

368-
test('Integrations are returned if feature flag is false and mode is dev', async (t) => {
397+
test('Integrations are returned if accountId is present and mode is dev', async (t) => {
369398
const { output } = await new Fixture('./fixtures/base')
370399
.withFlags({
371400
siteId: 'test',
372401
mode: 'dev',
373402
token: 'test',
403+
accountId: 'account1',
374404
})
375-
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
405+
.runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
376406

377407
const config = JSON.parse(output)
378408

379409
t.assert(config.integrations)
380410
t.assert(config.integrations.length === 1)
381411
t.assert(config.integrations[0].slug === 'test')
382-
t.assert(config.integrations[0].version === 'so-cool')
412+
t.assert(config.integrations[0].version === 'so-cool-v2')
383413
t.assert(config.integrations[0].has_build === true)
384414
})
385415

0 commit comments

Comments
 (0)