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
29 changes: 29 additions & 0 deletions src/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
getCommentId,
getLatestDiscussionCommentId,
isEnterpriseHost,
addHours,
formatSearchQueryString,
} from './helpers';
import {
mockedSingleNotification,
Expand Down Expand Up @@ -147,4 +149,31 @@ describe('utils/helpers.ts', () => {
expect(result).toBe('https://github.manos.im/api/v3/');
});
});

describe('addHours', () => {
// Example test using Jest
test('adds hours correctly for positive values', () => {
const result = addHours('2024-02-20T12:00:00.000Z', 3);
expect(result).toBe('2024-02-20T15:00:00.000Z');
});

test('adds hours correctly for negative values', () => {
const result = addHours('2024-02-20T12:00:00.000Z', -2);
expect(result).toBe('2024-02-20T10:00:00.000Z');
});
});

describe('formatSearchQueryString', () => {
test('formats search query string correctly', () => {
const result = formatSearchQueryString(
'exampleRepo',
'exampleTitle',
'2024-02-20T12:00:00.000Z',
);

expect(result).toBe(
`exampleTitle in:title repo:exampleRepo updated:>2024-02-20T10:00:00.000Z`,
);
});
});
});
21 changes: 15 additions & 6 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,22 @@ export function generateGitHubWebUrl(
return newUrl + comment;
}

const addHours = (date: string, hours: number) =>
new Date(new Date(date).getTime() + hours * 36e5).toISOString();
export function addHours(date: string, hours: number): string {
return new Date(new Date(date).getTime() + hours * 36e5).toISOString();
}

const queryString = (repo: string, title: string, lastUpdated: string) =>
`${title} in:title repo:${repo} updated:>${addHours(lastUpdated, -2)}`;
export function formatSearchQueryString(
repo: string,
title: string,
lastUpdated: string,
): string {
return `${title} in:title repo:${repo} updated:>${addHours(lastUpdated, -2)}`;
}

async function getReleaseTagWebUrl(notification: Notification, token: string) {
export async function getReleaseTagWebUrl(
notification: Notification,
token: string,
) {
const response = await apiRequestAuth(notification.subject.url, 'GET', token);

return {
Expand All @@ -89,7 +98,7 @@ async function getDiscussionUrl(
token,
{
query: `{
search(query:"${queryString(
search(query:"${formatSearchQueryString(
notification.repository.full_name,
notification.subject.title,
notification.updated_at,
Expand Down