diff --git a/setupTests.ts b/setupTests.ts index 3260e6c..dbf4e01 100644 --- a/setupTests.ts +++ b/setupTests.ts @@ -19,3 +19,8 @@ global.FormData = JSDOMFormData process.env.BASE_URL = "http://localhost" enableFetchMocks() + +afterAll(() => { + jest.restoreAllMocks() + jest.resetModules() +}) diff --git a/show-watcher/notifications/create.ts b/show-watcher/notifications/create.ts new file mode 100644 index 0000000..1743ff2 --- /dev/null +++ b/show-watcher/notifications/create.ts @@ -0,0 +1,21 @@ +interface TackUpNotification { + name: Name + params: Params + subscriptionJson: any + start: () => void +} + +type TackUpNotifications = + TackUpNotification<"left to go in class", { + classNumber: number, + leftToGo: number + }> | + + + + + + +function create(type: NotificationType["name"], params: NotificationType["params"]) { + +} \ No newline at end of file diff --git a/show-watcher/notifications/leftToGoInClass.ts b/show-watcher/notifications/leftToGoInClass.ts new file mode 100644 index 0000000..d93f9ad --- /dev/null +++ b/show-watcher/notifications/leftToGoInClass.ts @@ -0,0 +1,21 @@ + +function buildLeftToGoInClass({ data }) { + + function buildNotification({ data: }) { + const leftToGo = getLeftToGoInClass(data.classNumber) + const className = getClassNameFromClassNumber(data.classNumber) + return { + title: `There are ${leftToGo} left to go in ${className}` + } + } + + function startWatch() { + watchClass({number: data.classNumber}, ) + } + + return { + buildNotification, + + } +} + diff --git a/show-watcher/notify.ts b/show-watcher/notify.ts new file mode 100644 index 0000000..5a58b30 --- /dev/null +++ b/show-watcher/notify.ts @@ -0,0 +1,9 @@ +interface NotificationParams { + title: string, + badge: +} + +export default function notify(recipientSubscriptionJSON: any, notification: { + title: string, + options: NotificationOptions +}) {} diff --git a/show-watcher/register.test.ts b/show-watcher/register.test.ts new file mode 100644 index 0000000..f70b053 --- /dev/null +++ b/show-watcher/register.test.ts @@ -0,0 +1,41 @@ +import register from "./register" +import watch from "./watch" +import notify from "./notify" + +jest.mock("./watch") +jest.mock("./notify") + +const mockedNotify = jest.mocked(notify) +const mockedWatch = jest.mocked(watch) + +const recipientSubscriptionJSON = { + endpoint: "https://zombo.com", + expirationTime: null, + keys: { + auth: "O_JFRKmhy3OU9LfpfWeQ8Q", + p256dh: "somegoofystring", + }, +} + +describe("register", () => { + beforeEach(() => { + mockedWatch.mockImplementation(() => jest.fn()) + }) + + test("starts a watch for the provided event", () => { + register({ + type: "left to go in class", + data: { + count: 5, + class: 2102, + }, + recipientSubscriptionJSON, + }) + + const watchCallback = mockedWatch.mock.calls[0][0].callback + + expect(mockedNotify).toHaveBeenCalledWith(recipientSubscriptionJSON, { + title: "5 left to go in class 2102", + }) + }) +}) diff --git a/show-watcher/register.ts b/show-watcher/register.ts new file mode 100644 index 0000000..7d99875 --- /dev/null +++ b/show-watcher/register.ts @@ -0,0 +1,22 @@ +import notify from "./notify" +import watch from "./watch" + +export default function register({ + type, + data, + recipientSubscriptionJSON, +}: { + type: string + data: any + recipientSubscriptionJSON: any +}) { + function onNotify() { + notify(recipientSubscriptionJSON) + } + + watch({ + type, + data, + callback: onNotify, + }) +} diff --git a/show-watcher/tests/leftToGoInClass.test.ts b/show-watcher/tests/leftToGoInClass.test.ts new file mode 100644 index 0000000..e8b3681 --- /dev/null +++ b/show-watcher/tests/leftToGoInClass.test.ts @@ -0,0 +1,3 @@ +describe("Left to go in class notification", () => { + test("") +}) diff --git a/show-watcher/tests/mockSubscriptionJson.ts b/show-watcher/tests/mockSubscriptionJson.ts new file mode 100644 index 0000000..e69de29 diff --git a/show-watcher/watch.ts b/show-watcher/watch.ts new file mode 100644 index 0000000..5f7618f --- /dev/null +++ b/show-watcher/watch.ts @@ -0,0 +1,9 @@ +export default function watch({ + type, + data, + callback, +}: { + type: string + data: any + callback: () => void +}) {}