Skip to content

Commit eaf7883

Browse files
committed
Fix updateConfigWithPersonalAccessKey again
1 parent 062aa9a commit eaf7883

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org/

config/__tests__/config.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,6 @@ describe('config/index', () => {
314314

315315
expect(getConfigAccountEnvironment(123)).toEqual('qa');
316316
});
317-
318-
it('returns default account environment when no identifier', () => {
319-
mockConfig();
320-
321-
expect(getConfigAccountEnvironment()).toEqual('qa');
322-
});
323317
});
324318

325319
describe('addConfigAccount()', () => {

config/__tests__/utils.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
isConfigAccountValid,
1616
getAccountIdentifierAndType,
1717
} from '../utils';
18+
import { HubSpotConfigError } from '../../models/HubSpotConfigError';
1819
import { getCwd } from '../../lib/path';
1920
import {
2021
DeprecatedHubSpotConfigAccountFields,
@@ -195,12 +196,12 @@ describe('config/utils', () => {
195196
expect(result).toBe('config contents');
196197
});
197198

198-
it('throws FileSystemError on read failure', () => {
199+
it('throws HubSpotConfigError on read failure', () => {
199200
mockFs.readFileSync.mockImplementation(() => {
200201
throw new Error('Read error');
201202
});
202203

203-
expect(() => readConfigFile('test')).toThrow(FileSystemError);
204+
expect(() => readConfigFile('test')).toThrow(HubSpotConfigError);
204205
});
205206
});
206207

lib/__tests__/personalAccessKey.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ describe('lib/personalAccessKey', () => {
657657
);
658658
});
659659

660-
it('uses existing account name when name not provided', async () => {
660+
it('uses existing account name when updating by name', async () => {
661661
const existingAccount = {
662662
accountId: 123,
663663
name: 'existing-name',
@@ -671,7 +671,7 @@ describe('lib/personalAccessKey', () => {
671671
},
672672
},
673673
};
674-
getConfigDefaultAccountIfExists.mockReturnValue(existingAccount);
674+
getConfigAccountIfExists.mockReturnValue(existingAccount);
675675

676676
const freshAccessToken = 'fresh-token';
677677
fetchAccessToken.mockResolvedValue(
@@ -689,7 +689,12 @@ describe('lib/personalAccessKey', () => {
689689

690690
const token = await getAccessToken('pak_123', ENVIRONMENTS.QA, 123);
691691

692-
await updateConfigWithAccessToken(token, 'pak_123', ENVIRONMENTS.QA);
692+
await updateConfigWithAccessToken(
693+
token,
694+
'pak_123',
695+
ENVIRONMENTS.QA,
696+
'existing-name'
697+
);
693698

694699
expect(updateConfigAccount).toHaveBeenCalledWith(
695700
expect.objectContaining({

lib/personalAccessKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export async function updateConfigWithAccessToken(
182182
makeDefault = false
183183
): Promise<PersonalAccessKeyConfigAccount> {
184184
const { portalId, accessToken, expiresAt, accountType } = token;
185-
const account = name ? getConfigAccountIfExists(name) : undefined;
185+
const account = getConfigAccountIfExists(portalId);
186186
const accountEnv = env || account?.env || ENVIRONMENTS.PROD;
187187

188188
let parentAccountId;

0 commit comments

Comments
 (0)