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

chore: (Notifications) enable linting on __tests__ #13438

Merged
merged 4 commits into from
May 29, 2024
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
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {
'packages/datastore-storage-adapter/__tests__',
// 'packages/geo/__tests__',
'packages/interactions/__tests__',
'packages/notifications/__tests__',
// 'packages/notifications/__tests__',
elorzafe marked this conversation as resolved.
Show resolved Hide resolved
'packages/predictions/__tests__',
'packages/pubsub/__tests__',
'packages/react-native/__tests__',
Expand Down Expand Up @@ -90,6 +90,9 @@ module.exports = {
'delivery_type',
'treatment_id',
'campaign_activity_id',
'journey_activity_id',
'journey_run_id',
'journey_id',
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Event listeners', () => {
});

it('can handle async error', async () => {
const mockHandler = jest.fn().mockImplementation(() => {
mockHandler.mockImplementation(() => {
throw new Error();
});
const params = { foo: 'foo' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

import { defaultStorage } from '@aws-amplify/core';

import {
clearMessages,
initializeInAppMessaging,
} from '../../../../../src/inAppMessaging/providers/pinpoint/apis';
import {
STORAGE_KEY_SUFFIX,
PINPOINT_KEY_PREFIX,
STORAGE_KEY_SUFFIX,
} from '../../../../../src/inAppMessaging/providers/pinpoint/utils';
import { InAppMessagingError } from '../../../../../src/inAppMessaging/errors';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { defaultStorage } from '@aws-amplify/core';

import {
dispatchEvent,
initializeInAppMessaging,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';

import {
identifyUser,
initializeInAppMessaging,
} from '../../../../../src/inAppMessaging/providers/pinpoint/apis';
import {
resolveCredentials,
resolveConfig,
getInAppMessagingUserAgentString,
CATEGORY,
CHANNEL_TYPE,
getInAppMessagingUserAgentString,
resolveConfig,
resolveCredentials,
} from '../../../../../src/inAppMessaging/providers/pinpoint/utils';
import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';

import { IdentifyUserInput } from '../../../../../src/inAppMessaging/providers/pinpoint/types';

jest.mock('@aws-amplify/core/internals/providers/pinpoint');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import { Hub } from '@aws-amplify/core';
import { sessionListener } from '@aws-amplify/core/internals/utils';

import {
notifyEventListeners,
addEventListener,
notifyEventListeners,
} from '../../../../../src/eventListeners';
import { initializeInAppMessaging } from '../../../../../src/inAppMessaging/providers/pinpoint/apis';
import { sessionListener } from '@aws-amplify/core/internals/utils';

jest.mock('@aws-amplify/core');
jest.mock('../../../../../src/eventListeners');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { inAppMessages } from '../../../../testUtils/data';
import {
notifyEventListeners,
addEventListener,
notifyEventListeners,
} from '../../../../../src/eventListeners';
import {
initializeInAppMessaging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
// SPDX-License-Identifier: Apache-2.0

import { defaultStorage } from '@aws-amplify/core';
import {
resolveEndpointId,
updateEndpoint,
} from '@aws-amplify/core/internals/providers/pinpoint';
import { getInAppMessages } from '@aws-amplify/core/internals/aws-clients/pinpoint';

import {
initializeInAppMessaging,
syncMessages,
} from '../../../../../src/inAppMessaging/providers/pinpoint/apis';
import {
STORAGE_KEY_SUFFIX,
resolveCredentials,
resolveConfig,
getInAppMessagingUserAgentString,
resolveConfig,
resolveCredentials,
} from '../../../../../src/inAppMessaging/providers/pinpoint/utils';
import { simpleInAppMessages } from '../../../../testUtils/data';
import {
updateEndpoint,
resolveEndpointId,
} from '@aws-amplify/core/internals/providers/pinpoint';
import { getInAppMessages } from '@aws-amplify/core/internals/aws-clients/pinpoint';
import { InAppMessagingError } from '../../../../../src/inAppMessaging/errors';

jest.mock('@aws-amplify/core/internals/aws-clients/pinpoint');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ import {
extractContent,
mapOSPlatform,
} from '../../../../../src/inAppMessaging/providers/pinpoint/utils/helpers';

import {
nonBrowserConfigTestCases,
pinpointInAppMessage,
extractedContent,
nativeButtonOverrides,
nonBrowserConfigTestCases,
pinpointInAppMessage,
} from '../../../../testUtils/data';
import { mergeExpectedContentWithExpectedOverride, mergeInAppMessageWithOverrides } from '../../../../testUtils/mergeInAppMessageWithOverrides';
import {
mergeExpectedContentWithExpectedOverride,
mergeInAppMessageWithOverrides,
} from '../../../../testUtils/mergeInAppMessageWithOverrides';

jest.mock('@aws-amplify/core');

jest.mock('@aws-amplify/core/internals/utils', () => {
const originalModule = jest.requireActual(
'@aws-amplify/core/internals/utils',
);

return {
...originalModule,
getClientInfo: jest.fn(), // Setup as a Jest mock function without implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import {
matchesEventType,
matchesMetrics,
} from '../../../../../src/inAppMessaging/providers/pinpoint/utils/helpers';

import {
browserButtonOverrides,
browserConfigTestCases,
extractedContent,
extractedMetadata,
pinpointInAppMessage,
browserConfigTestCases,
browserButtonOverrides,
} from '../../../../testUtils/data';
import { InAppMessagingEvent } from '../../../../../src/inAppMessaging/types';
import { InAppMessagingEvent } from '../../../../../src/inAppMessaging/types';
import {
mergeExpectedContentWithExpectedOverride,
mergeInAppMessageWithOverrides,
Expand All @@ -37,6 +36,7 @@ jest.mock('@aws-amplify/core/internals/utils', () => {
const originalModule = jest.requireActual(
'@aws-amplify/core/internals/utils',
);

return {
...originalModule,
getClientInfo: jest.fn(), // Setup as a Jest mock function without implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import { resolveConfig } from '../../../../../src/inAppMessaging/providers/pinpoint/utils';

describe('resolveConfig', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { fetchAuthSession } from '@aws-amplify/core';

import { resolveCredentials } from '../../../../../src/inAppMessaging/providers/pinpoint/utils';

jest.mock('@aws-amplify/core');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { cloneDeep } from 'lodash';

import {
pinpointInAppMessage,
simpleInAppMessagingEvent,
Expand All @@ -9,7 +11,6 @@ import {
incrementMessageCounts,
processInAppMessages,
} from '../../../src/inAppMessaging/providers/pinpoint/utils';
import { cloneDeep } from 'lodash';
import {
isBeforeEndDate,
matchesAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getEndpointId,
updateEndpoint,
} from '@aws-amplify/core/internals/providers/pinpoint';

import { assertIsInitialized } from '../../../../../src/pushNotifications/errors/errorHelpers';
import { identifyUser } from '../../../../../src/pushNotifications/providers/pinpoint/apis/identifyUser.native';
import { IdentifyUserInput } from '../../../../../src/pushNotifications/providers/pinpoint/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';

import {
notifyEventListeners,
notifyEventListenersAndAwaitHandlers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { expectNotSupported } from '../../../../testUtils/expectNotSupported';

describe('getBadgeCount', () => {
it('is only supported on React Native', () => {
expectNotSupported(() => setBadgeCount(42));
expectNotSupported(() => {
setBadgeCount(42);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

import { record } from '@aws-amplify/core/internals/providers/pinpoint';

import { resolveCredentials } from '../../../../../src/pushNotifications/utils';
import { getAnalyticsEvent } from '../../../../../src/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent';
import { getChannelType } from '../../../../../src/pushNotifications/providers/pinpoint/utils/getChannelType';
import { resolveConfig } from '../../../../../src/pushNotifications/providers/pinpoint/utils/resolveConfig';
import { createMessageEventRecorder } from '../../../../../src/pushNotifications/providers/pinpoint/utils/createMessageEventRecorder';

import {
analyticsEvent,
channelType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import { getAnalyticsEvent } from '../../../../../src/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent';

import {
androidCampaignData,
androidJourneyData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import {
getInflightDeviceRegistration,
rejectInflightDeviceRegistration,
resolveInflightDeviceRegistration,
} from '../../../../../src/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration';
Comment on lines -4 to -8
Copy link
Contributor

Choose a reason for hiding this comment

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

do you know why it was imported and also declared as variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That looks like it was removed from lint --fix they must have been removed since they are not used. Probably missed artifact

import { InflightDeviceRegistration } from '../../../../../src/pushNotifications/providers/pinpoint/types';

describe('inflightDeviceRegistration', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PushNotificationAction,
getAmplifyUserAgent,
} from '@aws-amplify/core/internals/utils';

import { getPushNotificationUserAgentString } from '../../../src/pushNotifications/utils/getPushNotificationUserAgentString';
import { userAgentValue } from '../../testUtils/data';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import { resolveConfig } from '../../../src/pushNotifications/providers/pinpoint/utils/resolveConfig';
import { pinpointConfig } from '../../testUtils/data';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { fetchAuthSession } from '@aws-amplify/core';

import { resolveCredentials } from '../../../src/pushNotifications/utils';
import { credentials } from '../../testUtils/data';

Expand Down
3 changes: 2 additions & 1 deletion packages/notifications/__tests__/testUtils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
import {
type InAppMessageCampaign as PinpointInAppMessage,
OverrideButtonConfiguration,
type InAppMessageCampaign as PinpointInAppMessage,
} from '@aws-amplify/core/internals/aws-clients/pinpoint';

import {
InAppMessage,
InAppMessageContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
InAppMessageCampaign,
OverrideButtonConfiguration,
} from '@aws-amplify/core/internals/aws-clients/pinpoint';

import {
ButtonConfigPlatform,
InAppMessageButton,
Expand Down Expand Up @@ -34,6 +35,7 @@ export const mergeInAppMessageWithOverrides = (
},
};
}

return message;
};

Expand All @@ -44,7 +46,7 @@ export const mergeExpectedContentWithExpectedOverride = (
secondaryButton: OverrideButtonConfiguration;
},
): InAppMessageContent => {
let expectedContent = cloneDeep(inAppMessage);
const expectedContent = cloneDeep(inAppMessage);
expectedContent.primaryButton = {
...expectedContent.primaryButton,
action: expectedButtonConfig.primaryButton.ButtonAction,
Expand All @@ -55,5 +57,6 @@ export const mergeExpectedContentWithExpectedOverride = (
action: expectedButtonConfig.secondaryButton.ButtonAction,
url: expectedButtonConfig.secondaryButton.Link,
} as InAppMessageButton;

return expectedContent;
};
};
Loading