Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): return account id from config in offline mode #5810

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading