Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
oklemenz2 committed Jan 26, 2024
1 parent 960c141 commit 52f87a1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed

- Refactor middlewares and authorization check
- Change `cds.ws` to point to CDS websocket server (not the native implementation, use `cds.wss` or `cds.io` for that)
- Change `cds.ws` to point to CDS websocket server (not the native implementation, use `cds.wss` or `cds.io` for that)

## Version 0.4.0 - 2024-01-26

Expand Down
3 changes: 1 addition & 2 deletions src/socket/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ class SocketServer {
* @param {integer} code Reason code for close
* @param {string} reason Reason text for close
*/
close(socket, code, reason) {
}
close(socket, code, reason) {}

/**
* Middlewares executed before
Expand Down
2 changes: 1 addition & 1 deletion test/auth_socketio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("Auth", () => {
socket.on("disconnect", () => {
resolve();
});
})
});
emitEvent(socket, "message", { text: "test" });
cds.ws.close(socket);
cds.ws.close();
Expand Down
2 changes: 1 addition & 1 deletion test/auth_ws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("Auth", () => {
expect(String(reason)).toEqual(`{"error":{"code":"401","message":"Unauthorized"}}`);
resolve();
});
})
});
emitEvent(socket, "message", { text: "test" });
cds.ws.close(socket);
cds.ws.close();
Expand Down
26 changes: 12 additions & 14 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ const cds = require("@sap/cds");
const SocketServer = require("../src/socket/base");

describe("Base", () => {
beforeAll(async () => {
});
beforeAll(async () => {});

afterAll(() => {
});
afterAll(() => {});

test("Instance", async () => {
const socketServer = new SocketServer();
Expand All @@ -29,15 +27,15 @@ describe("Base", () => {
emit: expect.any(Function),
broadcast: expect.any(Function),
broadcastAll: expect.any(Function),
disconnect: expect.any(Function)
disconnect: expect.any(Function),
});
expect(socket.setup()).toBeUndefined();
expect(socket.context()).toMatchObject({
id: null,
user: null,
tenant: null,
http: { req: null, res: null },
ws: { service: expect.any(Object), socket: null }
ws: { service: expect.any(Object), socket: null },
});
expect(socket.on()).toBeUndefined();
expect(socket.emit()).toBeUndefined();
Expand All @@ -55,32 +53,32 @@ describe("Base", () => {
expect(req.res.headers).toEqual({});
expect(req.res.set("A", "B")).toBe(req.res);
expect(req.res.headers).toEqual({
A: "B"
A: "B",
});
expect(req.res.set("x-correlation-id", "123")).toBe(req.res);
expect(req.correlationId).toEqual("123");
expect(req.res.headers).toEqual({
A: "B",
"x-correlation-id": "123"
"x-correlation-id": "123",
});
expect(req.res.setHeader("X", "Y")).toBe(req.res);
expect(req.res.headers).toEqual({
A: "B",
X: "Y",
"x-correlation-id": "123"
"x-correlation-id": "123",
});
expect(req.res.status(200)).toBe(req.res);
expect(req.res.statusCode).toEqual(200);
expect(
req.res.writeHead(201, "Created", {
X: "Z"
})
X: "Z",
}),
).toBe(req.res);
expect(req.res.statusCode).toEqual(201);
expect(req.res.headers).toEqual({
A: "B",
X: "Z",
"x-correlation-id": "123"
"x-correlation-id": "123",
});
expect(req.res.json({ A: 1 })).toBe(req.res);
expect(req.res.body).toEqual({ A: 1 });
Expand All @@ -96,8 +94,8 @@ describe("Base", () => {
const request = {
headers: {
authorization: "",
cookie: "X-Authorization=Basic YWxpY2U6YWxpY2U"
}
cookie: "X-Authorization=Basic YWxpY2U6YWxpY2U",
},
};
const next = jest.fn();
const socketServer = new SocketServer();
Expand Down

0 comments on commit 52f87a1

Please sign in to comment.