Skip to content

Commit

Permalink
use the new utility function to obtain the region api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
demetriusfeijoo committed Feb 29, 2024
1 parent 9074893 commit 6ab10ae
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { getRegionBaseUrl, EU_CODE } = require('@storyblok/region-helper')
const { EU_CODE } = require('@storyblok/region-helper')
const { getRegionApiEndpoint } = require('./utils/region')

const SYNC_TYPES = ['folders', 'components', 'roles', 'stories', 'datasources']

const COMMANDS = {
Expand All @@ -23,8 +25,6 @@ const DEFAULT_AGENT = {
SB_Agent_Version: process.env.npm_package_version || '3.0.0'
}

const getRegionApiEndpoint = (region) => `${getRegionBaseUrl(region)}/v1/`

// todo: FIND OUT IF THIS WORKS WITH us
const USERS_ROUTES = {
LOGIN: `${getRegionApiEndpoint(EU_CODE)}users/login`,
Expand All @@ -35,6 +35,5 @@ module.exports = {
SYNC_TYPES,
USERS_ROUTES,
COMMANDS,
DEFAULT_AGENT,
getRegionApiEndpoint
DEFAULT_AGENT
}
3 changes: 2 additions & 1 deletion src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const inquirer = require('inquirer')

const creds = require('./creds')
const getQuestions = require('./get-questions')
const { getRegionApiEndpoint, USERS_ROUTES, DEFAULT_AGENT } = require('../constants')
const { USERS_ROUTES, DEFAULT_AGENT } = require('../constants')
const { getRegionApiEndpoint } = require('./region')
const { EU_CODE } = require('@storyblok/region-helper')

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
capitalize: require('./capitalize'),
findByProperty: require('./find-by-property'),
parseError: require('./parse-error'),
region: require('./region'),
saveFileFactory: require('./save-file-factory')
}
4 changes: 2 additions & 2 deletions src/utils/region.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { getRegionBaseUrl } = require('@storyblok/region-helper')

const getManagementBaseURLByRegion = (region) => `${getRegionBaseUrl(region)}/v1/`
const getRegionApiEndpoint = (region) => `${getRegionBaseUrl(region)}/v1/`

module.exports = {
getManagementBaseURLByRegion
getRegionApiEndpoint
}
4 changes: 2 additions & 2 deletions tests/units/list-spaces.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ describe('Test spaces method', () => {
res: [...FAKE_SPACES()]
},
{
key: AP_CODE,
key: CA_CODE,
res: [...FAKE_SPACES()]
},
{
key: CA_CODE,
key: AP_CODE,
res: [...FAKE_SPACES()]
}
]
Expand Down
2 changes: 1 addition & 1 deletion tests/units/push-components.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const pushComponents = require('../../src/tasks/push-components')
const Storyblok = require('storyblok-js-client')
const api = require('../../src/utils/api')
const { getRegionApiEndpoint } = require('../../src/constants')
const { getRegionApiEndpoint } = require('../../src/utils/region')
const { EU_CODE } = require('@storyblok/region-helper')

jest.mock('fs')
Expand Down
2 changes: 1 addition & 1 deletion tests/units/quickstart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const quickstart = require('../../src/tasks/quickstart')
const Storyblok = require('storyblok-js-client')
const api = require('../../src/utils/api')
const { getRegionApiEndpoint } = require('../../src/constants')
const { getRegionApiEndpoint } = require('../../src/utils/region')
const { EU_CODE } = require('@storyblok/region-helper')

jest.unmock('fs')
Expand Down
2 changes: 1 addition & 1 deletion tests/units/scaffold.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs')
const scaffold = require('../../src/tasks/scaffold')
const Storyblok = require('storyblok-js-client')
const api = require('../../src/utils/api')
const { getRegionApiEndpoint } = require('../../src/constants')
const { getRegionApiEndpoint } = require('../../src/utils/region')
const { EU_CODE } = require('@storyblok/region-helper')

jest.mock('fs')
Expand Down
2 changes: 1 addition & 1 deletion tests/units/sync.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sync = require('../../src/tasks/sync')
const Storyblok = require('storyblok-js-client')
const { getRegionApiEndpoint } = require('../../src/constants')
const { getRegionApiEndpoint } = require('../../src/utils/region')
const { EU_CODE } = require('@storyblok/region-helper')

jest.unmock('axios')
Expand Down

0 comments on commit 6ab10ae

Please sign in to comment.