mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 07:24:53 +09:00
Remove SubscriptionResponse
Since subscriptions are handlede per link there's no need for the eventReplay to be returned as a part of the SubscriptionRequest, it can be sent and processed normally as an event. Simplify the logic by sending eventReplay as an event and remove SubscriptionResponse.
This commit is contained in:
1 parent
4439691695
commit
6cab1fa842
3 files changed
+11
-116
No files matched your search
@@ -46,46 +46,6 @@ describe("lib/subscriptions", function() {
|
||||
}
|
||||
}
|
||||
|
||||
describe("class SubscriptionResponse", function() {
|
||||
it("should be round trip json serialisable without an event replay", function() {
|
||||
const response = new lib.SubscriptionResponse();
|
||||
const json = JSON.stringify(response);
|
||||
assert.equal(typeof json, "string");
|
||||
const reconstructed = lib.SubscriptionResponse.fromJSON(JSON.parse(json));
|
||||
assert.deepEqual(reconstructed, response);
|
||||
});
|
||||
|
||||
it("should be round trip json serialisable with an event replay", function() {
|
||||
const response = new lib.SubscriptionResponse(new RegisteredEvent());
|
||||
const json = JSON.stringify(response);
|
||||
assert.equal(typeof json, "string");
|
||||
const reconstructed = lib.SubscriptionResponse.fromJSON(JSON.parse(json));
|
||||
assert.deepEqual(reconstructed, response);
|
||||
});
|
||||
|
||||
it("should be round trip json serialisable with an undefined event replay", function() {
|
||||
const response = new lib.SubscriptionResponse(undefined);
|
||||
const json = JSON.stringify(response);
|
||||
assert.equal(typeof json, "string");
|
||||
const reconstructed = lib.SubscriptionResponse.fromJSON(JSON.parse(json));
|
||||
assert.deepEqual(reconstructed, response);
|
||||
});
|
||||
|
||||
it("should be throw when given an unregistered event in a json", function() {
|
||||
assert.throws(
|
||||
() => lib.SubscriptionResponse.fromJSON([UnregisteredEvent.name, {}]),
|
||||
new Error(`Unregistered Event class ${UnregisteredEvent.name}`)
|
||||
);
|
||||
});
|
||||
|
||||
it("should be throw when given an unregistered event", function() {
|
||||
assert.throws(
|
||||
() => new lib.SubscriptionResponse(new UnregisteredEvent()),
|
||||
new Error(`Unregistered Event class ${UnregisteredEvent.name}`)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("class SubscriptionRequest", function() {
|
||||
describe("permission()", function() {
|
||||
function newSubscriptionRequestMessage(request) {
|
||||
@@ -440,22 +400,6 @@ describe("lib/subscriptions", function() {
|
||||
await events.once(mockControl.connector, "send");
|
||||
assertLastRequest(expected);
|
||||
});
|
||||
it("should call handlers when a replay event is returned", async function() {
|
||||
let calledWith = null;
|
||||
const event = new RegisteredEvent();
|
||||
const request = registeredEvent.subscribe(function(value) { calledWith = value; });
|
||||
await events.once(mockControl.connector, "send");
|
||||
|
||||
mockControl.connector.emit("message", new lib.MessageResponse(
|
||||
0,
|
||||
mockControl.connector.dst,
|
||||
new lib.Address(lib.Address.control, 0, mockControl._nextRequestId - 1),
|
||||
new lib.SubscriptionResponse(event).toJSON()
|
||||
));
|
||||
|
||||
await request;
|
||||
assert.deepEqual(calledWith, event);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user