Skip to content

Commit

Permalink
fix imports and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Dec 16, 2024
1 parent f31b0ff commit 72709ab
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 61 deletions.
10 changes: 5 additions & 5 deletions commands/project/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ const {
addUseEnvironmentOptions,
} = require('../../../lib/commonOpts');
const { loadAndValidateOptions } = require('../../../lib/validation');
const {
getProjectConfig,
pollDeployStatus,
getProjectDetailUrl,
} = require('../../../lib/projects');
const { getProjectConfig } = require('../../../lib/projects');
const { getProjectDetailUrl } = require('../../../lib/projects/urls');
const { pollDeployStatus } = require('../../../lib/projects/buildAndDeploy');
const { projectNamePrompt } = require('../../../lib/prompts/projectNamePrompt');
const { promptUser } = require('../../../lib/prompts/promptUtils');
const { trackCommandUsage } = require('../../../lib/usageTracking');
Expand All @@ -35,6 +33,8 @@ jest.mock('@hubspot/local-dev-lib/config');
jest.mock('../../../lib/commonOpts');
jest.mock('../../../lib/validation');
jest.mock('../../../lib/projects');
jest.mock('../../../lib/projects/urls');
jest.mock('../../../lib/projects/buildAndDeploy');
jest.mock('../../../lib/prompts/projectNamePrompt');
jest.mock('../../../lib/prompts/promptUtils');
jest.mock('../../../lib/usageTracking');
Expand Down
8 changes: 3 additions & 5 deletions commands/project/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ const {
fetchProject,
} = require('@hubspot/local-dev-lib/api/projects');
const { loadAndValidateOptions } = require('../../lib/validation');
const {
getProjectConfig,
pollDeployStatus,
getProjectDetailUrl,
} = require('../../lib/projects');
const { getProjectConfig } = require('../../lib/projects');
const { pollDeployStatus } = require('../../lib/projects/buildAndDeploy');
const { getProjectDetailUrl } = require('../../lib/projects/urls');
const { projectNamePrompt } = require('../../lib/prompts/projectNamePrompt');
const { promptUser } = require('../../lib/prompts/promptUtils');
const { i18n } = require('../../lib/lang');
Expand Down
2 changes: 1 addition & 1 deletion commands/project/listBuilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const { uiBetaTag, uiLink } = require('../../lib/ui');
const { loadAndValidateOptions } = require('../../lib/validation');
const {
getProjectConfig,
getProjectDetailUrl,
validateProjectConfig,
} = require('../../lib/projects');
const { getProjectDetailUrl } = require('../../lib/projects/urls');
const moment = require('moment');
const { promptUser } = require('../../lib/prompts/promptUtils');
const { isHubSpotHttpError } = require('@hubspot/local-dev-lib/errors/index');
Expand Down
7 changes: 2 additions & 5 deletions commands/project/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ const { trackCommandUsage } = require('../../lib/usageTracking');
const { loadAndValidateOptions } = require('../../lib/validation');
const { i18n } = require('../../lib/lang');
const { logger } = require('@hubspot/local-dev-lib/logger');
const {
getProjectConfig,
getProjectDetailUrl,
ensureProjectExists,
} = require('../../lib/projects');
const { getProjectConfig, ensureProjectExists } = require('../../lib/projects');
const { getProjectDetailUrl } = require('../../lib/projects/urls');
const { projectNamePrompt } = require('../../lib/prompts/projectNamePrompt');
const { uiBetaTag } = require('../../lib/ui');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
Expand Down
6 changes: 4 additions & 2 deletions commands/project/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const {
handleProjectUpload,
logFeedbackMessage,
validateProjectConfig,
pollProjectBuildAndDeploy,
displayWarnLogs,
} = require('../../lib/projects');
const {
displayWarnLogs,
pollProjectBuildAndDeploy,
} = require('../../lib/projects/buildAndDeploy');
const { i18n } = require('../../lib/lang');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index');
Expand Down
6 changes: 4 additions & 2 deletions commands/project/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ const {
ensureProjectExists,
getProjectConfig,
handleProjectUpload,
pollDeployStatus,
validateProjectConfig,
logFeedbackMessage,
} = require('../../lib/projects');
const { pollBuildStatus } = require('../../lib/projectTasks');
const {
pollBuildStatus,
pollDeployStatus,
} = require('../../lib/projects/buildAndDeploy');
const {
cancelStagedBuild,
fetchProjectBuilds,
Expand Down
8 changes: 4 additions & 4 deletions lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,6 @@ en:
notFound: "Your project {{#bold}}{{ projectName }}{{/bold}} could not be found in {{#bold}}{{ accountIdentifier }}{{/bold}}."
pollFetchProject:
checkingProject: "Checking if project exists in {{ accountIdentifier }}"
pollProjectBuildAndDeploy:
buildSucceededAutomaticallyDeploying: "Build #{{ buildId }} succeeded. {{#bold}}Automatically deploying{{/bold}} to {{ accountIdentifier }}\n"
cleanedUpTempFile: "Cleaned up temporary file {{ path }}"
viewDeploys: "View all deploys for this project in HubSpot"
unableToFindAutodeployStatus: "Unable to find the auto deploy for build #{{ buildId }}. This deploy may have been skipped. {{ viewDeploysLink }}."
logFeedbackMessage:
feedbackHeader: "We'd love to hear your feedback!"
Expand All @@ -1132,6 +1128,10 @@ en:
failedStatusText: "FAILED"
errorFetchingTaskStatus: "Error fetching {{ taskType }} status"
pollBuildAutodeployStatusError: "Error fetching autodeploy status for build #{{ buildId }}"
pollProjectBuildAndDeploy:
buildSucceededAutomaticallyDeploying: "Build #{{ buildId }} succeeded. {{#bold}}Automatically deploying{{/bold}} to {{ accountIdentifier }}\n"
cleanedUpTempFile: "Cleaned up temporary file {{ path }}"
viewDeploys: "View all deploys for this project in HubSpot"
ui:
betaTag: "{{#bold}}[BETA]{{/bold}}"
betaWarning:
Expand Down
2 changes: 1 addition & 1 deletion lib/LocalDevManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { PROJECT_CONFIG_FILE } = require('./constants');
const SpinniesManager = require('./ui/SpinniesManager');
const DevServerManager = require('./DevServerManager');
const { EXIT_CODES } = require('./enums/exitCodes');
const { getProjectDetailUrl } = require('./projects');
const { getProjectDetailUrl } = require('./projects/urls');
const { getAccountHomeUrl } = require('./localDev');
const {
CONFIG_FILES,
Expand Down
2 changes: 2 additions & 0 deletions lib/doctor/__tests__/Diagnosis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('lib/doctor/Diagnosis', () => {
projectDir: 'project-dir',
projectConfig: {
name: 'Super cool project',
srcDir: 'project-dir',
platformVersion: 'test',
},
},
},
Expand Down
14 changes: 8 additions & 6 deletions lib/doctor/__tests__/DiagnosticInfoBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { AccessToken, CLIAccount } from '@hubspot/local-dev-lib/types/Accounts';
import { getProjectConfig as _getProjectConfig } from '../../projects';
import { fetchProject as _fetchProject } from '@hubspot/local-dev-lib/api/projects';
import { Project } from '@hubspot/local-dev-lib/types/Project';
import { AxiosPromise } from 'axios';
import { HubSpotPromise } from '@hubspot/local-dev-lib/types/Http';

const walk = _walk as jest.MockedFunction<typeof _walk>;
const getAccessToken = _getAccessToken as jest.MockedFunction<
Expand Down Expand Up @@ -124,6 +124,8 @@ describe('lib/doctor/DiagnosticInfo', () => {
projectDir,
projectConfig: {
name: 'My project',
srcDir: 'project-dir',
platformVersion: 'test',
},
};

Expand All @@ -133,7 +135,7 @@ describe('lib/doctor/DiagnosticInfo', () => {
deployedBuildId: 1,
id: 8989898,
isLocked: false,
name: projectConfig.projectConfig.name,
name: projectConfig!.projectConfig!.name,
portalId: accountId,
updatedAt: 12345,
};
Expand All @@ -143,16 +145,16 @@ describe('lib/doctor/DiagnosticInfo', () => {
accountType: 'STANDARD',
encodedOAuthRefreshToken: '',
expiresAt: '',
hubName: projectConfig.projectConfig.name,
hubName: projectConfig!.projectConfig!.name,
portalId: accountId,
scopeGroups: [],
enabledFeatures: {},
};

getProjectConfig.mockResolvedValue(projectConfig);
fetchProject.mockResolvedValue(({
fetchProject.mockResolvedValue({
data: projectDetails,
} as unknown) as AxiosPromise<Project>);
} as unknown as HubSpotPromise<Project>);
getAccessToken.mockResolvedValue(accessToken);
getConfigPath.mockReturnValue(configPath);
utilPromisify.mockReturnValue(jest.fn().mockResolvedValue(npmVersion));
Expand All @@ -166,7 +168,7 @@ describe('lib/doctor/DiagnosticInfo', () => {
expect(fetchProject).toHaveBeenCalledTimes(1);
expect(fetchProject).toHaveBeenCalledWith(
accountId,
projectConfig!.projectConfig.name
projectConfig!.projectConfig!.name
);

expect(getAccessToken).toHaveBeenCalledTimes(1);
Expand Down
36 changes: 21 additions & 15 deletions lib/doctor/__tests__/Doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ jest.mock('util', () => ({
const hasMissingPackages = _hasMissingPackages as jest.MockedFunction<
typeof _hasMissingPackages
>;
const isPortManagerPortAvailable = _isPortManagerPortAvailable as jest.MockedFunction<
typeof _isPortManagerPortAvailable
>;
const isPortManagerPortAvailable =
_isPortManagerPortAvailable as jest.MockedFunction<
typeof _isPortManagerPortAvailable
>;

const utilPromisify = util.promisify as jest.MockedFunction<
typeof util.promisify
>;

const accessTokenForPersonalAccessKey = _accessTokenForPersonalAccessKey as jest.MockedFunction<
typeof _accessTokenForPersonalAccessKey
>;
const accessTokenForPersonalAccessKey =
_accessTokenForPersonalAccessKey as jest.MockedFunction<
typeof _accessTokenForPersonalAccessKey
>;

const isSpecifiedError = _isSpecifiedError as jest.MockedFunction<
typeof _isSpecifiedError
Expand All @@ -64,7 +66,11 @@ describe('lib/doctor/Doctor', () => {
project: {
config: {
projectDir: '/path/to/project',
projectConfig: {},
projectConfig: {
name: 'my-project',
srcDir: '/path/to/project',
platformVersion: 'test',
},
},
},
versions: {
Expand All @@ -75,11 +81,11 @@ describe('lib/doctor/Doctor', () => {
};

beforeEach(() => {
doctor = new Doctor(({
doctor = new Doctor({
generateDiagnosticInfo: jest.fn().mockResolvedValue({
...diagnosticInfo,
}),
} as unknown) as DiagnosticInfoBuilder);
} as unknown as DiagnosticInfoBuilder);

utilPromisify.mockReturnValue(
jest.fn().mockImplementationOnce((filename: string) => {
Expand All @@ -104,12 +110,12 @@ describe('lib/doctor/Doctor', () => {
});

it('should add error section if node version is not available', async () => {
doctor = new Doctor(({
doctor = new Doctor({
generateDiagnosticInfo: jest.fn().mockResolvedValue({
...diagnosticInfo,
versions: {},
}),
} as unknown) as DiagnosticInfoBuilder);
} as unknown as DiagnosticInfoBuilder);

await doctor.diagnose();

Expand All @@ -121,12 +127,12 @@ describe('lib/doctor/Doctor', () => {
});

it('should add error section if minimum node version is not met', async () => {
doctor = new Doctor(({
doctor = new Doctor({
generateDiagnosticInfo: jest.fn().mockResolvedValue({
...diagnosticInfo,
versions: { node: '1.0.0' },
}),
} as unknown) as DiagnosticInfoBuilder);
} as unknown as DiagnosticInfoBuilder);

await doctor.diagnose();

Expand All @@ -149,12 +155,12 @@ describe('lib/doctor/Doctor', () => {
});

it('should add error section if npm is not installed', async () => {
doctor = new Doctor(({
doctor = new Doctor({
generateDiagnosticInfo: jest.fn().mockResolvedValue({
...diagnosticInfo,
versions: {},
}),
} as unknown) as DiagnosticInfoBuilder);
} as unknown as DiagnosticInfoBuilder);

await doctor.diagnose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ exports[`lib/doctor/DiagnosticInfo generateDiagnosticInfo should gather the requ
"config": {
"projectConfig": {
"name": "My project",
"platformVersion": "test",
"srcDir": "project-dir",
},
"projectDir": "/Users/test/project",
},
Expand Down
16 changes: 6 additions & 10 deletions lib/localDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ const {
isAppDeveloperAccount,
isDeveloperTestAccount,
} = require('./accountTypes');
const {
handleProjectUpload,
pollProjectBuildAndDeploy,
} = require('./projects');
const { handleProjectUpload } = require('./projects');
const { pollProjectBuildAndDeploy } = require('./projects/buildAndDeploy');
const {
PROJECT_ERROR_TYPES,
PROJECT_BUILD_TEXT,
Expand Down Expand Up @@ -248,9 +246,8 @@ const createDeveloperTestAccountForLocalDev = async (
let currentPortalCount = 0;
let maxTestPortals = 10;
try {
const validateResult = await validateDevTestAccountUsageLimits(
accountConfig
);
const validateResult =
await validateDevTestAccountUsageLimits(accountConfig);
if (validateResult) {
currentPortalCount = validateResult.results
? validateResult.results.length
Expand Down Expand Up @@ -306,9 +303,8 @@ const createDeveloperTestAccountForLocalDev = async (

// Prompt user to confirm usage of an existing developer test account that is not currently in the config
const useExistingDevTestAccount = async (env, account) => {
const useExistingDevTestAcct = await confirmUseExistingDeveloperTestAccountPrompt(
account
);
const useExistingDevTestAcct =
await confirmUseExistingDeveloperTestAccountPrompt(account);
if (!useExistingDevTestAcct) {
logger.log('');
logger.log(
Expand Down
4 changes: 2 additions & 2 deletions lib/projects/buildAndDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function makePollTaskStatusFunc<T extends ProjectTask>({
};
}

export function pollBuildAutodeployStatus(
function pollBuildAutodeployStatus(
accountId: number,
taskName: string,
buildId: number
Expand Down Expand Up @@ -430,7 +430,7 @@ export const pollBuildStatus = makePollTaskStatusFunc<Build>({
},
});

const pollDeployStatus = makePollTaskStatusFunc<Deploy>({
export const pollDeployStatus = makePollTaskStatusFunc<Deploy>({
linkToHubSpot: (accountId, taskName, taskId, deployedBuildId) =>
uiLink(
`View deploy of build #${deployedBuildId} in HubSpot`,
Expand Down
2 changes: 2 additions & 0 deletions lib/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,10 @@ export async function handleProjectUpload<T = ProjectUploadDefaultResult>(
);

if (error) {
console.log(error);
uploadResult = { uploadError: error };
} else if (callbackFunc) {
console.log('callbackfunc');
uploadResult = await callbackFunc(
accountId,
projectConfig,
Expand Down
6 changes: 3 additions & 3 deletions lib/projects/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const chokidar = require('chokidar');
const path = require('path');
const chalk = require('chalk');
const { default: PQueue } = require('p-queue');
const { logError, ApiErrorContext } = require('./errorHandlers/index');
const { i18n } = require('./lang');
const { logError, ApiErrorContext } = require('../errorHandlers/index');
const { i18n } = require('../lang');
const { logger } = require('@hubspot/local-dev-lib/logger');
const { isAllowedExtension } = require('@hubspot/local-dev-lib/path');
const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules');
Expand All @@ -16,7 +16,7 @@ const {
queueBuild,
} = require('@hubspot/local-dev-lib/api/projects');
const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index');
const { PROJECT_ERROR_TYPES } = require('./constants');
const { PROJECT_ERROR_TYPES } = require('../constants');

const i18nKey = 'commands.project.subcommands.watch';

Expand Down

0 comments on commit 72709ab

Please sign in to comment.