Skip to content

Commit

Permalink
Merge pull request #65 from HubSpot/br-unit-tests-11
Browse files Browse the repository at this point in the history
Tests for object utils (and other small fixes)
  • Loading branch information
brandenrodgers authored Nov 15, 2023
2 parents 661ddee + 2a0c326 commit 1c6144d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export function getValidEnv(
env?: Environment | null,
maskedProductionValue?: Environment
): Environment {
const prodValue = maskedProductionValue
? maskedProductionValue
: ENVIRONMENTS.PROD;
const prodValue =
typeof maskedProductionValue === 'string'
? maskedProductionValue
: ENVIRONMENTS.PROD;

const returnVal =
typeof env &&
Expand Down
4 changes: 2 additions & 2 deletions lib/validate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs-extra';
import { HUBL_EXTENSIONS } from '../constants/extensions';
import { validateHubl } from '../api/validateHubl';
import { walk } from '../lib/fs';
import { getExt } from '../lib/path';
import { walk } from './fs';
import { getExt } from './path';
import { LintResult } from '../types/HublValidation';

export async function lint(
Expand Down
5 changes: 4 additions & 1 deletion models/OAuth2Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class OAuth2Manager {
this.writeTokenInfo = writeTokenInfo;
this.refreshTokenRequest = null;
this.account = account;
// NOTE: Potential issues by not using maskProductionValue = '' for env like in cli-lib

if (this.account.env) {
this.account.env = getValidEnv(this.account.env, '');
}
}

async accessToken(): Promise<string | undefined> {
Expand Down
38 changes: 38 additions & 0 deletions utils/__tests__/objectUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mergeDeep, isObject } from '../objectUtils';

describe('utils/objectUtils', () => {
describe('isObject()', () => {
it('should return false for non objects', () => {
expect(isObject('foo')).toBeFalsy();
expect(isObject(null)).toBeFalsy();
expect(isObject(1)).toBeFalsy();
});

it('should return true for objects', () => {
expect(isObject({})).toBeTruthy();
expect(isObject({ some: 'object' })).toBeTruthy();
});
});

describe('mergeDeep()', () => {
it('should merge simple objects', () => {
const object1 = { a: 'a' };
const object2 = { b: 'b' };
const object3 = { c: 'c' };

const result = mergeDeep(object1, object2, object3);

expect(result).toMatchObject({ a: 'a', b: 'b', c: 'c' });
});

it('should deeply merge nested objects', () => {
const object1 = { a: { a: 'a' } };
const object2 = { a: { b: 'b' } };
const object3 = { a: { c: 'c' } };

const result = mergeDeep(object1, object2, object3);

expect(result).toMatchObject({ a: { a: 'a', b: 'b', c: 'c' } });
});
});
});
2 changes: 1 addition & 1 deletion utils/objectUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isObject(item: any) {
export function isObject(item: any) {
return item && typeof item === 'object' && !Array.isArray(item);
}

Expand Down

0 comments on commit 1c6144d

Please sign in to comment.