Skip to content

Commit

Permalink
fix(socketio): add support for ack callbacks (#2680)
Browse files Browse the repository at this point in the history
closes #2679
  • Loading branch information
derevnjuk authored Apr 25, 2024
1 parent 90b1baa commit 184cb76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ describe("SocketHandlersBuilder", () => {
});
});
describe("deserialize()", () => {
it("should call ConverterService.deserialize", () => {
it("should call deserialize on args", () => {
const provider: any = {
store: {
get: jest.fn()
Expand Down Expand Up @@ -953,5 +953,34 @@ describe("SocketHandlersBuilder", () => {
args: [["any"]]
});
});

it("should map ack callback without deserialization", () => {
const provider: any = {
store: {
get: jest.fn()
}
};
const parameters: any[] = [
{
filter: SocketFilters.ARGS,
useMapper: true,
mapIndex: 0,
type: Function
}
];
const ack = () => {};
const scope: any = {
args: [ack]
};

const builder = new SocketHandlersBuilder(provider, PlatformTest.injector);

// @ts-ignore
builder.deserialize({parameters} as any, scope as any);

expect(scope).toEqual({
args: [ack]
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@ export class SocketHandlersBuilder {
const {filter, useMapper, mapIndex, type, collectionType} = parameters![index];
let value = scope.args[mapIndex!];

if (filter === SocketFilters.ARGS && useMapper) {
value = deserialize(value, {
type,
collectionType,
useAlias: true
});
if (filter === SocketFilters.ARGS) {
if (useMapper && typeof value !== "function") {
value = deserialize(value, {
type,
collectionType,
useAlias: true
});
}
scope.args[mapIndex!] = value;
}
});
Expand Down

0 comments on commit 184cb76

Please sign in to comment.