Skip to content

Commit

Permalink
Merge pull request #22 from HubSpot/pull-in-local-dev-lib
Browse files Browse the repository at this point in the history
Move config module to local-dev-lib
  • Loading branch information
camden11 authored Oct 31, 2023
2 parents 78c60db + 1c06d3a commit d5d2e0f
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 1,493 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/errorHandlers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { StatusCodeError } = require('request-promise-native/errors');
const { getAccountConfig } = require('../lib/config');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { fetchScopeData } = require('../api/localDevAuth/authenticated');
const {
ApiErrorContext,
Expand All @@ -9,7 +9,7 @@ const {
} = require('../errorHandlers');
const { LOG_LEVEL, logger } = require('../logger');

jest.mock('../lib/config');
jest.mock('@hubspot/local-dev-lib/config');
jest.mock('../logger');
jest.mock('../api/localDevAuth/authenticated');

Expand Down
7 changes: 5 additions & 2 deletions __tests__/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const requestPN = require('request-promise-native');
const request = require('request');
const fs = require('fs-extra');
const moment = require('moment');
const { getAndLoadConfigIfNeeded, getAccountConfig } = require('../lib/config');
const {
getAndLoadConfigIfNeeded,
getAccountConfig,
} = require('@hubspot/local-dev-lib/config');
const { ENVIRONMENTS } = require('../lib/constants');
const http = require('../http');
const { version } = require('../package.json');
Expand All @@ -13,7 +16,7 @@ jest.mock('request-promise-native', () => ({
}));

jest.mock('request');
jest.mock('../lib/config');
jest.mock('@hubspot/local-dev-lib/config');
jest.mock('../logger');

describe('http', () => {
Expand Down
33 changes: 14 additions & 19 deletions __tests__/hubdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,28 @@ jest.mock('../path');
jest.mock('../api/hubdb');

describe('cli-lib/hubdb', () => {
it('downloads hubdb table', async () => {
describe('downloadHubDbTable', () => {
const accountId = 123;
const tableId = 456;
const destPath = 'tmp.json';
const projectCwd = '/home/tom/projects';

getCwd.mockReturnValue(projectCwd);

hubdb.fetchRows.mockReturnValue(hubdbFetchRowResponse);
hubdb.fetchTable.mockReturnValue(hubdbFetchTableResponse);

const { filePath } = await downloadHubDbTable(accountId, tableId, destPath);
const fileOutput = JSON.parse(fs.outputFile.mock.results[0].value);
it('fetches all results', async () => {
const { filePath } = await downloadHubDbTable(
accountId,
tableId,
destPath
);
const fileOutput = JSON.parse(fs.outputFile.mock.results[0].value);

describe('outputs correct rows', () => {
expect(fileOutput.rows.length).toBe(3);
expect(fileOutput.rows[1].name).toBe('My Better Event');
});

describe('tranforms column ids to names', () => {
expect(fileOutput.rows[0].values['second_col']).toBe('b');
});
describe('provides data with correct name', () => {
expect(fileOutput.name).toBe('cool-table-name');
});
describe('returns destination file path', () => {
expect(filePath).toEqual(`${projectCwd}/${destPath}`);
});
});
Expand All @@ -66,7 +62,7 @@ describe('cli-lib/hubdb', () => {
});
});

it('uploads hubdb table', async () => {
describe('createHubDbTable', () => {
const accountId = 123;
const srcPath = 'tmp.json';
const projectCwd = '/home/tom/projects';
Expand All @@ -78,15 +74,14 @@ describe('cli-lib/hubdb', () => {
hubdb.createRows.mockReturnValue(hubdbCreateRowsResponse);
hubdb.publishTable.mockReturnValue(hubdbPublishTableResponse);

const table = await createHubDbTable(accountId, `${projectCwd}/${srcPath}`);
it('creates a table', async () => {
const table = await createHubDbTable(
accountId,
`${projectCwd}/${srcPath}`
);

describe('has the correct number of rows', () => {
expect(table.rowCount).toEqual(3);
});
describe('returns the correct table ID', () => {
expect(table.tableId).toEqual(2639452);
});
describe('publishes the table', () => {
expect(hubdb.publishTable).toBeCalled();
});
});
Expand Down
7 changes: 5 additions & 2 deletions __tests__/personalAccessKey.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const moment = require('moment');
const { getAndLoadConfigIfNeeded, getAccountConfig } = require('../lib/config');
const {
getAndLoadConfigIfNeeded,
getAccountConfig,
} = require('@hubspot/local-dev-lib/config');
const { fetchAccessToken } = require('../api/localDevAuth/unauthenticated');
const { ENVIRONMENTS } = require('../lib/constants');

const { accessTokenForPersonalAccessKey } = require('../personalAccessKey');

jest.mock('../lib/config');
jest.mock('@hubspot/local-dev-lib/config');
jest.mock('../logger');
jest.mock('../api/localDevAuth/unauthenticated');

Expand Down
2 changes: 1 addition & 1 deletion api/fileMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const contentDisposition = require('content-disposition');
const http = require('../http');
const { getCwd } = require('../path');
const { getEnv, getAccountConfig } = require('../lib/config');
const { getEnv, getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { logger } = require('../logger');

const FILE_MAPPER_API_PATH = 'content/filemapper/v1';
Expand Down
3 changes: 2 additions & 1 deletion errorHandlers/apiErrors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');

const { logger } = require('../logger');
const { getAccountConfig } = require('../lib/config');
const {
SCOPE_GROUPS,
PERSONAL_ACCESS_KEY_AUTH_METHOD,
Expand Down
2 changes: 1 addition & 1 deletion http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const request = require('request');
const requestPN = require('request-promise-native');
const fs = require('fs-extra');
const contentDisposition = require('content-disposition');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');

const { getAccountConfig } = require('./lib/config');
const { getRequestOptions } = require('./http/requestOptions');
const { accessTokenForPersonalAccessKey } = require('./personalAccessKey');
const { getOauthManager } = require('./oauth');
Expand Down
2 changes: 1 addition & 1 deletion http/requestOptions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { version } = require('../package.json');
const { getAndLoadConfigIfNeeded } = require('../lib/config');
const { getAndLoadConfigIfNeeded } = require('@hubspot/local-dev-lib/config');
const { getHubSpotApiOrigin } = require('../lib/urls');

const DEFAULT_USER_AGENT_HEADERS = {
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { ALLOWED_EXTENSIONS, Mode, DEFAULT_MODE } = require('./lib/constants');
const {
getAndLoadConfigIfNeeded,
getConfig,
Expand All @@ -14,7 +13,9 @@ const {
isConfigFlagEnabled,
isTrackingAllowed,
writeConfig,
} = require('./lib/config');
} = require('@hubspot/local-dev-lib/config');

const { ALLOWED_EXTENSIONS, Mode, DEFAULT_MODE } = require('./lib/constants');
const { checkAndWarnGitInclusion } = require('./lib/git');
const { hasUploadErrors, uploadFolder } = require('./lib/uploadFolder');
const { watch } = require('./lib/watch');
Expand Down
Loading

0 comments on commit d5d2e0f

Please sign in to comment.