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

Convert lib/serverlessLogs and lib/buildAccount to TS #1337

Merged
merged 12 commits into from
Jan 16, 2025
8 changes: 1 addition & 7 deletions commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ const endpointLog = async (accountId, functionPath, options) => {
}
};

await tailLogs({
accountId,
compact,
tailCall,
fetchLatest,
name: functionPath,
});
await tailLogs(accountId, functionPath, fetchLatest, tailCall, compact);
} else if (latest) {
try {
const { data } = await getLatestFunctionLog(accountId, functionPath);
Expand Down
12 changes: 6 additions & 6 deletions commands/sandbox/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
HUBSPOT_ACCOUNT_TYPES,
HUBSPOT_ACCOUNT_TYPE_STRINGS,
} = require('@hubspot/local-dev-lib/constants/config');
const { buildNewAccount } = require('../../lib/buildAccount');
const { buildSandbox } = require('../../lib/buildAccount');
const {
hubspotAccountNamePrompt,
} = require('../../lib/prompts/accountNamePrompt');
Expand Down Expand Up @@ -130,13 +130,13 @@ exports.handler = async options => {
}

try {
const { result } = await buildNewAccount({
name: sandboxName,
accountType: sandboxType,
const result = await buildSandbox(
sandboxName,
accountConfig,
sandboxType,
env,
force,
});
force
);

const sandboxAccountConfig = getAccountConfig(result.sandbox.sandboxHubId);
// For v1 sandboxes, keep sync here. Once we migrate to v2, this will be handled by BE automatically
Expand Down
2 changes: 1 addition & 1 deletion lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ en:
missingScopeError: "Couldn't execute the {{ request }} because the access key for {{ accountName }} is missing required scopes. To update scopes, run {{ authCommand }}. Then deactivate the existing key and generate a new one that includes the missing scopes."
serverless:
verifyAccessKeyAndUserAccess:
fetchScopeDataError: "Error verifying access of scopeGroup {{ scopeGroup }}: {{ error }}"
fetchScopeDataError: "Error verifying access of scopeGroup {{ scopeGroup }}:"
brandenrodgers marked this conversation as resolved.
Show resolved Hide resolved
portalMissingScope: "Your account does not have access to this action. Talk to an account admin to request it."
userMissingScope: "You don't have access to this action. Ask an account admin to change your permissions in Users & Teams settings."
genericMissingScope: "Your access key does not allow this action. Please generate a new access key by running `hs auth personalaccesskey`."
Expand Down
48 changes: 13 additions & 35 deletions lib/__tests__/serverlessLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ const ACCOUNT_ID = 123;
describe('lib/serverlessLogs', () => {
describe('tailLogs()', () => {
let stdinMock;
let spinnies;

beforeEach(() => {
jest.spyOn(process, 'exit').mockImplementation(() => {});
stdinMock = mockStdIn.stdin();
spinnies = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was being passed into tailLogs but not doing anything

succeed: jest.fn(),
fail: jest.fn(),
stopAll: jest.fn(),
};
});

afterEach(() => {
Expand All @@ -33,14 +27,16 @@ describe('lib/serverlessLogs', () => {
const compact = false;
const fetchLatest = jest.fn(() => {
return Promise.resolve({
id: '1234',
executionTime: 510,
log: 'Log message',
error: null,
status: 'SUCCESS',
createdAt: 1620232011451,
memory: '70/128 MB',
duration: '53.40 ms',
data: {
id: '1234',
executionTime: 510,
log: 'Log message',
error: null,
status: 'SUCCESS',
createdAt: 1620232011451,
memory: '70/128 MB',
duration: '53.40 ms',
},
});
});
const tailCall = jest.fn(() => {
Expand All @@ -54,13 +50,7 @@ describe('lib/serverlessLogs', () => {
});
});

await tailLogs({
accountId: ACCOUNT_ID,
compact,
spinnies,
fetchLatest,
tailCall,
});
await tailLogs(ACCOUNT_ID, 'name', fetchLatest, tailCall, compact);
jest.runOnlyPendingTimers();

expect(fetchLatest).toHaveBeenCalled();
Expand Down Expand Up @@ -116,13 +106,7 @@ describe('lib/serverlessLogs', () => {
Promise.resolve({ data: latestLogResponse })
);

await tailLogs({
accountId: ACCOUNT_ID,
compact,
spinnies,
fetchLatest,
tailCall,
});
await tailLogs(ACCOUNT_ID, 'name', fetchLatest, tailCall, compact);
jest.runOnlyPendingTimers();
expect(outputLogs).toHaveBeenCalledWith(
latestLogResponse,
Expand All @@ -148,13 +132,7 @@ describe('lib/serverlessLogs', () => {
)
);

await tailLogs({
accountId: ACCOUNT_ID,
compact,
spinnies,
fetchLatest,
tailCall,
});
await tailLogs(ACCOUNT_ID, 'name', fetchLatest, tailCall, compact);
jest.runOnlyPendingTimers();
expect(tailCall).toHaveBeenCalledTimes(2);
});
Expand Down
Loading
Loading