Skip to content

Commit 203f78e

Browse files
authored
test(helper): addDate and searchQueryString (#803)
1 parent d7d9d64 commit 203f78e

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

src/utils/helpers.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
getCommentId,
66
getLatestDiscussionCommentId,
77
isEnterpriseHost,
8+
addHours,
9+
formatSearchQueryString,
810
} from './helpers';
911
import {
1012
mockedSingleNotification,
@@ -147,4 +149,31 @@ describe('utils/helpers.ts', () => {
147149
expect(result).toBe('https://github.manos.im/api/v3/');
148150
});
149151
});
152+
153+
describe('addHours', () => {
154+
// Example test using Jest
155+
test('adds hours correctly for positive values', () => {
156+
const result = addHours('2024-02-20T12:00:00.000Z', 3);
157+
expect(result).toBe('2024-02-20T15:00:00.000Z');
158+
});
159+
160+
test('adds hours correctly for negative values', () => {
161+
const result = addHours('2024-02-20T12:00:00.000Z', -2);
162+
expect(result).toBe('2024-02-20T10:00:00.000Z');
163+
});
164+
});
165+
166+
describe('formatSearchQueryString', () => {
167+
test('formats search query string correctly', () => {
168+
const result = formatSearchQueryString(
169+
'exampleRepo',
170+
'exampleTitle',
171+
'2024-02-20T12:00:00.000Z',
172+
);
173+
174+
expect(result).toBe(
175+
`exampleTitle in:title repo:exampleRepo updated:>2024-02-20T10:00:00.000Z`,
176+
);
177+
});
178+
});
150179
});

src/utils/helpers.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,22 @@ export function generateGitHubWebUrl(
6565
return newUrl + comment;
6666
}
6767

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

71-
const queryString = (repo: string, title: string, lastUpdated: string) =>
72-
`${title} in:title repo:${repo} updated:>${addHours(lastUpdated, -2)}`;
72+
export function formatSearchQueryString(
73+
repo: string,
74+
title: string,
75+
lastUpdated: string,
76+
): string {
77+
return `${title} in:title repo:${repo} updated:>${addHours(lastUpdated, -2)}`;
78+
}
7379

74-
async function getReleaseTagWebUrl(notification: Notification, token: string) {
80+
export async function getReleaseTagWebUrl(
81+
notification: Notification,
82+
token: string,
83+
) {
7584
const response = await apiRequestAuth(notification.subject.url, 'GET', token);
7685

7786
return {
@@ -89,7 +98,7 @@ async function getDiscussionUrl(
8998
token,
9099
{
91100
query: `{
92-
search(query:"${queryString(
101+
search(query:"${formatSearchQueryString(
93102
notification.repository.full_name,
94103
notification.subject.title,
95104
notification.updated_at,

0 commit comments

Comments
 (0)