parent
7fb351fb0c
commit
c6ad10ca79
@ -1,5 +1,5 @@ |
|||||||
import { ResourceError } from "../../../requester/results/error/ErrorResult"; |
import { ResourceError } from "../../../requester/results/error/ErrorResult"; |
||||||
|
|
||||||
export class UnsupportedNotificationError extends ResourceError { |
export class UnsupportedNotificationError extends ResourceError { |
||||||
readonly type = "unexpectedResourceError" as const; |
readonly type = "unsupportedNotificationError" as const; |
||||||
} |
} |
||||||
|
@ -0,0 +1,57 @@ |
|||||||
|
import type { WebSocket, Event, ErrorEvent } from "ws"; |
||||||
|
import { Websocket2023NotificationSubscription } from "../src/resource/notifications/Websocket2023NotificationSubscription"; |
||||||
|
import type { SolidLdoDatasetContext } from "../src"; |
||||||
|
import { Leaf } from "../src"; |
||||||
|
import type { NotificationChannel } from "@solid-notifications/types"; |
||||||
|
|
||||||
|
describe("Websocket2023NotificationSubscription", () => { |
||||||
|
it("returns an error when websockets have an error", async () => { |
||||||
|
const WebSocketMock: WebSocket = {} as WebSocket; |
||||||
|
const onErrorMock = jest.fn(); |
||||||
|
|
||||||
|
const subscription = new Websocket2023NotificationSubscription( |
||||||
|
new Leaf("https://example.com", { |
||||||
|
fetch, |
||||||
|
} as unknown as SolidLdoDatasetContext), |
||||||
|
() => {}, |
||||||
|
onErrorMock, |
||||||
|
{} as unknown as SolidLdoDatasetContext, |
||||||
|
() => WebSocketMock, |
||||||
|
); |
||||||
|
|
||||||
|
const subPromise = subscription.subscribeToWebsocket({ |
||||||
|
receiveFrom: "http://example.com", |
||||||
|
} as unknown as NotificationChannel); |
||||||
|
WebSocketMock.onopen?.({} as Event); |
||||||
|
|
||||||
|
const subscriptionResult = await subPromise; |
||||||
|
expect(subscriptionResult.type).toBe("subscribeToNotificationSuccess"); |
||||||
|
|
||||||
|
WebSocketMock.onerror?.({ error: new Error("Test Error") } as ErrorEvent); |
||||||
|
|
||||||
|
expect(onErrorMock).toHaveBeenCalled(); |
||||||
|
}); |
||||||
|
|
||||||
|
it("returns an error when websockets have an error at the beginning", async () => { |
||||||
|
const WebSocketMock: WebSocket = {} as WebSocket; |
||||||
|
const onErrorMock = jest.fn(); |
||||||
|
|
||||||
|
const subscription = new Websocket2023NotificationSubscription( |
||||||
|
new Leaf("https://example.com", { |
||||||
|
fetch, |
||||||
|
} as unknown as SolidLdoDatasetContext), |
||||||
|
() => {}, |
||||||
|
onErrorMock, |
||||||
|
{} as unknown as SolidLdoDatasetContext, |
||||||
|
() => WebSocketMock, |
||||||
|
); |
||||||
|
|
||||||
|
const subPromise = subscription.subscribeToWebsocket({ |
||||||
|
receiveFrom: "http://example.com", |
||||||
|
} as unknown as NotificationChannel); |
||||||
|
WebSocketMock.onerror?.({ error: new Error("Test Error") } as ErrorEvent); |
||||||
|
const subscriptionResult = await subPromise; |
||||||
|
|
||||||
|
expect(subscriptionResult.type).toBe("unexpectedResourceError"); |
||||||
|
}); |
||||||
|
}); |
@ -0,0 +1,44 @@ |
|||||||
|
{ |
||||||
|
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld", |
||||||
|
"import": [ |
||||||
|
"css:config/app/init/initialize-root.json", |
||||||
|
"css:config/app/main/default.json", |
||||||
|
"css:config/app/variables/default.json", |
||||||
|
"css:config/http/handler/default.json", |
||||||
|
"css:config/http/middleware/default.json", |
||||||
|
"css:config/http/notifications/webhooks.json", |
||||||
|
"css:config/http/server-factory/http.json", |
||||||
|
"css:config/http/static/default.json", |
||||||
|
"css:config/identity/access/public.json", |
||||||
|
"css:config/identity/email/default.json", |
||||||
|
"css:config/identity/handler/no-accounts.json", |
||||||
|
"css:config/identity/oidc/default.json", |
||||||
|
"css:config/identity/ownership/token.json", |
||||||
|
"css:config/identity/pod/static.json", |
||||||
|
"css:config/ldp/authentication/dpop-bearer.json", |
||||||
|
"css:config/ldp/authorization/webacl.json", |
||||||
|
"css:config/ldp/handler/default.json", |
||||||
|
"css:config/ldp/metadata-parser/default.json", |
||||||
|
"css:config/ldp/metadata-writer/default.json", |
||||||
|
"css:config/ldp/modes/default.json", |
||||||
|
"css:config/storage/backend/file.json", |
||||||
|
"css:config/storage/key-value/resource-store.json", |
||||||
|
"css:config/storage/location/root.json", |
||||||
|
"css:config/storage/middleware/default.json", |
||||||
|
"css:config/util/auxiliary/acl.json", |
||||||
|
"css:config/util/identifiers/suffix.json", |
||||||
|
"css:config/util/index/default.json", |
||||||
|
"css:config/util/logging/winston.json", |
||||||
|
"css:config/util/representation-conversion/default.json", |
||||||
|
"css:config/util/resource-locker/file.json", |
||||||
|
"css:config/util/variables/default.json" |
||||||
|
], |
||||||
|
"@graph": [ |
||||||
|
{ |
||||||
|
"comment": [ |
||||||
|
"A Solid server that stores its resources on disk and uses WAC for authorization.", |
||||||
|
"No registration and the root container is initialized to allow full access for everyone so make sure to change this." |
||||||
|
] |
||||||
|
} |
||||||
|
] |
||||||
|
} |
Loading…
Reference in new issue