WIP, mostly just noodling
Test / test (push) Failing after 57s
Details
Test / test (push) Failing after 57s
Details
This commit is contained in:
parent
c684e2e31c
commit
a534a6c761
|
|
@ -19,3 +19,8 @@ global.FormData = JSDOMFormData
|
|||
process.env.BASE_URL = "http://localhost"
|
||||
|
||||
enableFetchMocks()
|
||||
|
||||
afterAll(() => {
|
||||
jest.restoreAllMocks()
|
||||
jest.resetModules()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
interface TackUpNotification<Name extends string, Params> {
|
||||
name: Name
|
||||
params: Params
|
||||
subscriptionJson: any
|
||||
start: () => void
|
||||
}
|
||||
|
||||
type TackUpNotifications =
|
||||
TackUpNotification<"left to go in class", {
|
||||
classNumber: number,
|
||||
leftToGo: number
|
||||
}> |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function create<NotificationType>(type: NotificationType["name"], params: NotificationType["params"]) {
|
||||
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
interface NotificationParams {
|
||||
title: string,
|
||||
badge:
|
||||
}
|
||||
|
||||
export default function notify(recipientSubscriptionJSON: any, notification: {
|
||||
title: string,
|
||||
options: NotificationOptions
|
||||
}) {}
|
||||
|
|
@ -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",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
describe("Left to go in class notification", () => {
|
||||
test("")
|
||||
})
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
export default function watch({
|
||||
type,
|
||||
data,
|
||||
callback,
|
||||
}: {
|
||||
type: string
|
||||
data: any
|
||||
callback: () => void
|
||||
}) {}
|
||||
Loading…
Reference in New Issue