Repository: gitify-app/gitify
Pull request #803 (2024-02-20 20:42:48)

test(helper): addDate and searchQueryString


Patch:
diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts
index e84fd3a5..fb71af3d 100644
--- a/src/utils/helpers.ts
+++ b/src/utils/helpers.ts
@@ -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 {
@@ -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,


Test patch:
diff --git a/src/utils/__snapshots__/github-api.test.ts.snap b/src/utils/__snapshots__/github-api.test.ts.snap
index 327ef366..f2aa1166 100644
--- a/src/utils/__snapshots__/github-api.test.ts.snap
+++ b/src/utils/__snapshots__/github-api.test.ts.snap
@@ -14,12 +14,7 @@ exports[`./utils/github-api.ts should format the notification color 6`] = `"text
 
 exports[`./utils/github-api.ts should format the notification color 7`] = `"text-green-500"`;
 
-exports[`./utils/github-api.ts should format the notification color 8`] = `
-{
-  "description": "The reason for this notification is not supported by the app.",
-  "type": "Unknown",
-}
-`;
+exports[`./utils/github-api.ts should format the notification color 8`] = `"text-gray-300"`;
 
 exports[`./utils/github-api.ts should format the notification reason 1`] = `
 {
diff --git a/src/utils/github-api.test.ts b/src/utils/github-api.test.ts
index 25ccac95..c0b31fb4 100644
--- a/src/utils/github-api.test.ts
+++ b/src/utils/github-api.test.ts
@@ -3,7 +3,7 @@ import {
   getNotificationTypeIcon,
   getNotificationTypeIconColor,
 } from './github-api';
-import { Reason, SubjectType } from '../typesGithub';
+import { Reason, StateType, SubjectType } from '../typesGithub';
 
 describe('./utils/github-api.ts', () => {
   it('should format the notification reason', () => {
@@ -75,6 +75,8 @@ describe('./utils/github-api.ts', () => {
     expect(getNotificationTypeIconColor('not_planned')).toMatchSnapshot();
     expect(getNotificationTypeIconColor('open')).toMatchSnapshot();
     expect(getNotificationTypeIconColor('reopened')).toMatchSnapshot();
-    expect(formatReason('something_else_unknown' as Reason)).toMatchSnapshot();
+    expect(
+      getNotificationTypeIconColor('something_else_unknown' as StateType),
+    ).toMatchSnapshot();
   });
 });
diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts
index ebaa908e..7ccfada9 100644
--- a/src/utils/helpers.test.ts
+++ b/src/utils/helpers.test.ts
@@ -5,6 +5,8 @@ import {
   getCommentId,
   getLatestDiscussionCommentId,
   isEnterpriseHost,
+  addHours,
+  formatSearchQueryString,
 } from './helpers';
 import {
   mockedSingleNotification,
@@ -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`,
+      );
+    });
+  });
 });