Compare commits

...

3 Commits

Author SHA1 Message Date
ad8441f72f Added build status to readme.me
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
2025-12-29 02:40:15 +00:00
ca3ba921be Added more tests. 2025-12-29 02:39:15 +00:00
15e260bcaa Added DS STORE 2025-12-29 02:38:49 +00:00
3 changed files with 20 additions and 5 deletions

3
.gitignore vendored
View File

@ -134,3 +134,6 @@ dist
*.env
test-results.xml
DS_STORE
**/DS_Store

View File

@ -1,5 +1,7 @@
# FarmControl WebSocket Service
[![Build Status](https://ci.tombutcher.work/buildStatus/icon?job=farmcontrol%2Ffarmcontrol-ws%2Fmain&style=flat-square)](https://ci.tombutcher.work/job/farmcontrol/job/farmcontrol-ws/job/main/)
A WebSocket microservice for FarmControl that handles real-time communication and distributed locking.
## Features

View File

@ -100,9 +100,15 @@ describe('SocketUser', () => {
it('should initialize correctly and setup event handlers', () => {
expect(mockSocket.use).toHaveBeenCalled();
expect(mockSocket.on).toHaveBeenCalledWith('authenticate', expect.any(Function));
expect(mockSocket.on).toHaveBeenCalledWith(
'authenticate',
expect.any(Function)
);
expect(mockSocket.on).toHaveBeenCalledWith('lock', expect.any(Function));
expect(mockSocket.on).toHaveBeenCalledWith('disconnect', expect.any(Function));
expect(mockSocket.on).toHaveBeenCalledWith(
'disconnect',
expect.any(Function)
);
});
describe('handleAuthenticateEvent', () => {
@ -111,11 +117,16 @@ describe('SocketUser', () => {
const callback = jest.fn();
const mockUser = { _id: 'user-id-obj', username: 'testuser' };
socketUser.keycloakAuth.verifyToken.mockResolvedValue({ valid: true, user: mockUser });
socketUser.keycloakAuth.verifyToken.mockResolvedValue({
valid: true,
user: mockUser
});
await socketUser.handleAuthenticateEvent(data, callback);
expect(socketUser.keycloakAuth.verifyToken).toHaveBeenCalledWith('valid-token');
expect(socketUser.keycloakAuth.verifyToken).toHaveBeenCalledWith(
'valid-token'
);
expect(socketUser.authenticated).toBe(true);
expect(socketUser.user).toEqual(mockUser);
expect(socketUser.id).toBe('user-id-obj');
@ -184,4 +195,3 @@ describe('SocketUser', () => {
});
});
});