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

fix: notification services controller missing env vars #4530

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -14,7 +14,8 @@ export function createMockNotificationEthSent(): OnChainRawNotification {
chain_id: 1,
block_number: 17485840,
block_timestamp: '2022-03-01T00:00:00Z',
tx_hash: '0x881D40237659C251811CEC9c364ef91dC08D300C',
tx_hash:
'0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6',
unread: true,
created_at: '2022-03-01T00:00:00Z',
address: '0x881D40237659C251811CEC9c364ef91dC08D300C',
Expand Down Expand Up @@ -48,7 +49,8 @@ export function createMockNotificationEthReceived(): OnChainRawNotification {
chain_id: 1,
block_number: 17485840,
block_timestamp: '2022-03-01T00:00:00Z',
tx_hash: '0x881D40237659C251811CEC9c364ef91dC08D300C',
tx_hash:
'0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6',
unread: true,
created_at: '2022-03-01T00:00:00Z',
address: '0x881D40237659C251811CEC9c364ef91dC08D300C',
Expand Down Expand Up @@ -82,7 +84,8 @@ export function createMockNotificationERC20Sent(): OnChainRawNotification {
chain_id: 1,
block_number: 17485840,
block_timestamp: '2022-03-01T00:00:00Z',
tx_hash: '0x881D40237659C251811CEC9c364ef91dC08D300C',
tx_hash:
'0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6',
unread: true,
created_at: '2022-03-01T00:00:00Z',
address: '0x881D40237659C251811CEC9c364ef91dC08D300C',
Expand Down Expand Up @@ -122,7 +125,8 @@ export function createMockNotificationERC20Received(): OnChainRawNotification {
chain_id: 1,
block_number: 17485840,
block_timestamp: '2022-03-01T00:00:00Z',
tx_hash: '0x881D40237659C251811CEC9c364ef91dC08D300C',
tx_hash:
'0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6',
unread: true,
created_at: '2022-03-01T00:00:00Z',
address: '0x881D40237659C251811CEC9c364ef91dC08D300C',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { mockFetchFeatureAnnouncementNotifications } from '../__fixtures__/mockS
import { TRIGGER_TYPES } from '../constants/notification-schema';
import { getFeatureAnnouncementNotifications } from './feature-announcements';

// Mocked type for testing, allows overwriting TS to test erroneous values
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type MockedType = any;

jest.mock('@contentful/rich-text-html-renderer', () => ({
documentToHtmlString: jest
.fn()
Expand All @@ -20,6 +24,27 @@ describe('Feature Announcement Notifications', () => {
jest.clearAllMocks();
});

it('should return an empty array if invalid environment provided', async () => {
mockFetchFeatureAnnouncementNotifications();

const assertEnvEmpty = async (
override: Partial<typeof featureAnnouncementsEnv>,
) => {
const result = await getFeatureAnnouncementNotifications({
...featureAnnouncementsEnv,
...override,
});
expect(result).toHaveLength(0);
};

await assertEnvEmpty({ accessToken: null as MockedType });
await assertEnvEmpty({ platform: null as MockedType });
await assertEnvEmpty({ spaceId: null as MockedType });
await assertEnvEmpty({ accessToken: '' });
await assertEnvEmpty({ platform: '' });
await assertEnvEmpty({ spaceId: '' });
});

it('should return an empty array if fetch fails', async () => {
const mockEndpoint = mockFetchFeatureAnnouncementNotifications({
status: 500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,14 @@ const fetchFeatureAnnouncementNotifications = async (
export async function getFeatureAnnouncementNotifications(
env: Env,
): Promise<INotification[]> {
const rawNotifications = await fetchFeatureAnnouncementNotifications(env);
const notifications = rawNotifications.map((notification) =>
processFeatureAnnouncement(notification),
);
if (env && env.accessToken && env.spaceId && env.platform) {
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved
const rawNotifications = await fetchFeatureAnnouncementNotifications(env);
const notifications = rawNotifications.map((notification) =>
processFeatureAnnouncement(notification),
);

return notifications;
}

return notifications;
return [];
}
Loading