@cratis/arc 22.137.0 → 22.138.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_a_direct_source_error.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_a_direct_source_error.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_a_direct_source_error.js +68 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_a_direct_source_error.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/for_ObservableQueryFor/when_subscribing/with_a_direct_source_error.ts +75 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@cratis/arc",
|
|
4
|
-
"version": "22.
|
|
4
|
+
"version": "22.138.1",
|
|
5
5
|
"description": "TypeScript command, query, validation, identity, and messaging runtime for Cratis Arc — the CQRS application framework for ASP.NET Core — used by generated proxies.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cratis",
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
import { given } from '../../../given.js';
|
|
6
|
+
import { Globals } from '../../../Globals.js';
|
|
7
|
+
import { QueryTransportMethod } from '../../QueryTransportMethod.js';
|
|
8
|
+
import { ObservableQuerySubscription } from '../../ObservableQuerySubscription.js';
|
|
9
|
+
import { an_observable_query_for } from '../given/an_observable_query_for.js';
|
|
10
|
+
|
|
11
|
+
for (const transport of [QueryTransportMethod.WebSocket, QueryTransportMethod.ServerSentEvents]) {
|
|
12
|
+
describe(`when subscribing with a direct source error over ${transport}`, given(an_observable_query_for, context => {
|
|
13
|
+
let callback: sinon.SinonStub;
|
|
14
|
+
let subscription: ObservableQuerySubscription<string>;
|
|
15
|
+
let originalDirect: boolean;
|
|
16
|
+
let originalTransport: QueryTransportMethod;
|
|
17
|
+
let originalWebSocket: typeof WebSocket;
|
|
18
|
+
let originalEventSourceFactory: typeof Globals.eventSourceFactory;
|
|
19
|
+
const failure = {
|
|
20
|
+
data: null,
|
|
21
|
+
isSuccess: false,
|
|
22
|
+
isReady: true,
|
|
23
|
+
isAuthorized: true,
|
|
24
|
+
isValid: true,
|
|
25
|
+
hasExceptions: true,
|
|
26
|
+
validationResults: [],
|
|
27
|
+
exceptionMessages: ['The source failed'],
|
|
28
|
+
exceptionStackTrace: '',
|
|
29
|
+
paging: { page: 0, size: 0, totalItems: 0, totalPages: 0 }
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
originalDirect = Globals.queryDirectMode;
|
|
34
|
+
originalTransport = Globals.queryTransportMethod;
|
|
35
|
+
originalWebSocket = globalThis.WebSocket;
|
|
36
|
+
originalEventSourceFactory = Globals.eventSourceFactory;
|
|
37
|
+
Globals.queryDirectMode = true;
|
|
38
|
+
Globals.queryTransportMethod = transport;
|
|
39
|
+
callback = sinon.stub();
|
|
40
|
+
const stream = {
|
|
41
|
+
readyState: 1,
|
|
42
|
+
onopen: null as (() => void) | null,
|
|
43
|
+
onclose: null,
|
|
44
|
+
onerror: null,
|
|
45
|
+
onmessage: null as ((event: { data: string }) => void) | null,
|
|
46
|
+
send: sinon.stub(),
|
|
47
|
+
close: sinon.stub()
|
|
48
|
+
};
|
|
49
|
+
const socket = sinon.stub().returns(stream);
|
|
50
|
+
Object.assign(socket, { CONNECTING: 0, OPEN: 1, CLOSING: 2, CLOSED: 3 });
|
|
51
|
+
(globalThis as Record<string, unknown>)['WebSocket'] = socket;
|
|
52
|
+
Globals.eventSourceFactory = () => stream as unknown as EventSource;
|
|
53
|
+
context.query.setOrigin('https://example.com');
|
|
54
|
+
subscription = context.query.subscribe(callback, { id: 'test-id' });
|
|
55
|
+
stream.onopen?.();
|
|
56
|
+
stream.onmessage?.({ data: JSON.stringify(failure) });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
subscription?.unsubscribe();
|
|
61
|
+
Globals.queryDirectMode = originalDirect;
|
|
62
|
+
Globals.queryTransportMethod = originalTransport;
|
|
63
|
+
globalThis.WebSocket = originalWebSocket;
|
|
64
|
+
Globals.eventSourceFactory = originalEventSourceFactory;
|
|
65
|
+
sinon.restore();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should deliver one failed result', () => {
|
|
69
|
+
callback.should.have.been.calledOnce;
|
|
70
|
+
callback.firstCall.args[0].isSuccess.should.be.false;
|
|
71
|
+
});
|
|
72
|
+
it('should expose the source error', () => callback.firstCall.args[0].exceptionMessages.should.deep.equal(['The source failed']));
|
|
73
|
+
it('should settle readiness', () => callback.firstCall.args[0].isReady.should.be.true);
|
|
74
|
+
}));
|
|
75
|
+
}
|