Skip to content

Commit

Permalink
fix(sdk): logging null breaks script (#2140)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes NAN-909

- Fix logging null should not throw an error
Added a test but `persistApi` is hard to mock so I had to use dryRun
  • Loading branch information
bodinsamuel committed May 10, 2024
1 parent c64fb01 commit bc44c1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/shared/lib/sdk/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export class NangoAction {
const lastArg = args[args.length - 1];

const isUserDefinedLevel = (object: UserLogParameters): boolean => {
return typeof lastArg === 'object' && 'level' in object;
return lastArg && typeof lastArg === 'object' && 'level' in object;
};

const userDefinedLevel: UserLogParameters | undefined = isUserDefinedLevel(lastArg) ? lastArg : undefined;
Expand Down
24 changes: 24 additions & 0 deletions packages/shared/lib/sdk/sync.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,27 @@ describe('Pagination', () => {
};
};
});

describe('Log', () => {
it('should not log if no activityLogId', async () => {
const nangoAction = new NangoAction({
secretKey: '***',
providerConfigKey: 'github',
connectionId: 'connection-1'
});
await expect(async () => {
await nangoAction.log('top');
}).rejects.toThrowError(new Error('There is no current activity log stream to log to'));
});

it('should not fail on null', async () => {
const nangoAction = new NangoAction({
secretKey: '***',
providerConfigKey: 'github',
connectionId: 'connection-1',
dryRun: true,
activityLogId: 1
});
await nangoAction.log(null);
});
});

0 comments on commit bc44c1a

Please sign in to comment.