Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,14 @@ describe('AnalyticsProvider test', () => {

test('error case', async () => {
const analytics = new AnalyticsProvider();
const mockError = { message: 'error' };

analytics.configure(options);
const spyon = jest
.spyOn(Pinpoint.prototype, 'updateEndpoint')
.mockImplementationOnce((params, callback) => {
callback({ message: 'error' }, null);
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 test was rejecting with callback is not a function and still passing, since it wasn't mocking this behavior correctly:
https://github.com/aws-amplify/amplify-js/blob/master/packages/analytics/src/Providers/AWSPinpointProvider.ts#L405-L407

});
.mockImplementationOnce(params => ({
promise: jest.fn().mockRejectedValue(mockError),
}));

jest.spyOn(Credentials, 'get').mockImplementationOnce(() => {
return Promise.resolve(credentials);
Expand All @@ -744,7 +746,29 @@ describe('AnalyticsProvider test', () => {
const params = { event: { name: '_update_endpoint', immediate: true } };

await analytics.record(params, { resolve, reject });
expect(reject).toBeCalled();
expect(reject).toBeCalledWith(mockError);
spyon.mockRestore();
});

test('BAD_REQUEST_CODE without message rejects error', async () => {
const analytics = new AnalyticsProvider();
const mockError = { debug: 'error', statusCode: 400 };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prior to the fix in a1b13da, this fails.


analytics.configure(options);
const spyon = jest
.spyOn(Pinpoint.prototype, 'updateEndpoint')
.mockImplementationOnce(params => ({
promise: jest.fn().mockRejectedValue(mockError),
}));

jest.spyOn(Credentials, 'get').mockImplementationOnce(() => {
return Promise.resolve(credentials);
});

const params = { event: { name: '_update_endpoint', immediate: true } };

await analytics.record(params, { resolve, reject });
expect(reject).toBeCalledWith(mockError);
spyon.mockRestore();
});
});
Expand Down
16 changes: 6 additions & 10 deletions packages/analytics/src/Providers/AWSPinpointProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,7 @@ export default class AWSPinpointProvider implements AnalyticsProvider {
typeof params.resendLimit === 'number' ? params.resendLimit : resendLimit;
if (params.resendLimit-- > 0) {
logger.debug(
`resending event ${params.eventName} with ${
params.resendLimit
} retry times left`
`resending event ${params.eventName} with ${params.resendLimit} retry times left`
);
this._pinpointPutEvents(params, handlers);
} else {
Expand Down Expand Up @@ -450,7 +448,9 @@ export default class AWSPinpointProvider implements AnalyticsProvider {
const { message } = err;
const { ApplicationId, EndpointRequest } = update_params;

if (!message.startsWith('Exceeded maximum endpoint per user count')) {
if (
!String(message).startsWith('Exceeded maximum endpoint per user count')
) {
return endpointObject.handlers.reject(err);
}

Expand Down Expand Up @@ -494,19 +494,15 @@ export default class AWSPinpointProvider implements AnalyticsProvider {

if (params.resendLimit-- > 0) {
logger.debug(
`resending endpoint update ${params.event.eventId} with ${
params.resendLimit
} retry attempts remaining`
`resending endpoint update ${params.event.eventId} with ${params.resendLimit} retry attempts remaining`
);
// insert at the front of endpointBuffer
this._endpointBuffer.unshift(endpointObject);
return;
}

logger.warn(
`resending endpoint update ${params.event.eventId} failed after ${
params.config.resendLimit
} attempts`
`resending endpoint update ${params.event.eventId} failed after ${params.config.resendLimit} attempts`
);

if (this._endpointGenerating) {
Expand Down