Skip to content

Commit

Permalink
feat(config): return account id from config in offline mode (#5810)
Browse files Browse the repository at this point in the history
  • Loading branch information
JGAntunes authored Aug 21, 2024
1 parent d5ef407 commit e82859d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
10 changes: 8 additions & 2 deletions packages/config/src/api/site_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const getSiteInfo = async function ({

if (useV2Endpoint) {
if (api === undefined || mode === 'buildbot' || testEnv) {
const siteInfo = siteId === undefined ? {} : { id: siteId }
const siteInfo: { id?: string; account_id?: string } = {}

if (siteId !== undefined) siteInfo.id = siteId
if (accountId !== undefined) siteInfo.account_id = accountId

const integrations =
mode === 'buildbot' && !offline
Expand Down Expand Up @@ -73,7 +76,10 @@ export const getSiteInfo = async function ({
}

if (api === undefined || mode === 'buildbot' || testEnv) {
const siteInfo = siteId === undefined ? {} : { id: siteId }
const siteInfo: { id?: string; account_id?: string } = {}

if (siteId !== undefined) siteInfo.id = siteId
if (accountId !== undefined) siteInfo.account_id = accountId

const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : []

Expand Down
37 changes: 27 additions & 10 deletions packages/config/tests/api/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ test('--site-id', async (t) => {
t.snapshot(normalizeOutput(output))
})

test('--account-id in offline and buildbot mode', async (t) => {
const output = await new Fixture('./fixtures/empty')
.withFlags({ accountId: 'test-account', offline: true, mode: 'buildbot' })
.runWithConfig([FETCH_INTEGRATIONS_EMPTY_RESPONSE])
const config = JSON.parse(output)

t.is(config.siteInfo.account_id, 'test-account')
})

test('NETLIFY_SITE_ID environment variable', async (t) => {
const output = await new Fixture('./fixtures/empty')
.withEnv({ NETLIFY_SITE_ID: 'test' })
Expand Down Expand Up @@ -333,7 +342,7 @@ test('Integrations are not returned if offline', async (t) => {
t.assert(config.integrations.length === 0)
})

test('Integrations are returned if feature flag is false and mode is buildbot', async (t) => {
test('Integrations and account id are returned if feature flag is false and mode is buildbot', async (t) => {
const { output } = await new Fixture('./fixtures/base')
.withFlags({
siteId: 'test',
Expand All @@ -346,10 +355,14 @@ test('Integrations are returned if feature flag is false and mode is buildbot',
const config = JSON.parse(output)

t.assert(config.integrations)
t.assert(config.integrations.length === 1)
t.assert(config.integrations[0].slug === 'test')
t.assert(config.integrations[0].version === 'so-cool')
t.assert(config.integrations[0].has_build === true)
t.is(config.integrations.length, 1)
t.is(config.integrations[0].slug, 'test')
t.is(config.integrations[0].version, 'so-cool')
t.is(config.integrations[0].has_build, true)

// account id is also available
t.assert(config.siteInfo)
t.is(config.siteInfo.account_id, 'account1')
})

test('Integrations are returned if feature flag is false and mode is dev', async (t) => {
Expand All @@ -370,7 +383,7 @@ test('Integrations are returned if feature flag is false and mode is dev', async
t.assert(config.integrations[0].has_build === true)
})

test('Integrations are returned if flag is true for site and mode is buildbot', async (t) => {
test('Integrations and account id are returned if flag is true for site and mode is buildbot', async (t) => {
const { output } = await new Fixture('./fixtures/base')
.withFlags({
siteId: 'test',
Expand All @@ -386,10 +399,14 @@ test('Integrations are returned if flag is true for site and mode is buildbot',
const config = JSON.parse(output)

t.assert(config.integrations)
t.assert(config.integrations.length === 1)
t.assert(config.integrations[0].slug === 'test')
t.assert(config.integrations[0].version === 'so-cool')
t.assert(config.integrations[0].has_build === true)
t.is(config.integrations.length, 1)
t.is(config.integrations[0].slug, 'test')
t.is(config.integrations[0].version, 'so-cool')
t.is(config.integrations[0].has_build, true)

// account id is also available
t.assert(config.siteInfo)
t.is(config.siteInfo.account_id, 'account1')
})

test('Integrations are returned if flag is true for site and mode is dev', async (t) => {
Expand Down

0 comments on commit e82859d

Please sign in to comment.