mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-23 06:12:23 +00:00
fix: Frontend code cleanup @Nerivec (#24322)
Co-authored-by: Nerivec <62446222+Nerivec@users.noreply.github.com>
This commit is contained in:
1 parent
618b318214
commit
e2f19f19b4
7 files changed
+89
-58
No files matched your search
+31
-1
@@ -358,7 +358,7 @@ describe('Frontend', () => {
|
||||
expect(mockWS.implementation.emit).toHaveBeenCalledWith('connection', mockWSocket, {url});
|
||||
});
|
||||
|
||||
it.each(['z2m', 'z2m/', '/z2m'])('Works with non-default base url %s', async (baseUrl) => {
|
||||
it.each(['/z2m/', '/z2m'])('Works with non-default base url %s', async (baseUrl) => {
|
||||
settings.set(['frontend'], {base_url: baseUrl});
|
||||
controller = new Controller(jest.fn(), jest.fn());
|
||||
await controller.start();
|
||||
@@ -382,4 +382,34 @@ describe('Frontend', () => {
|
||||
expect(mockNodeStatic.implementation).not.toHaveBeenCalled();
|
||||
expect(mockFinalHandler.implementation).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('Works with non-default complex base url', async () => {
|
||||
const baseUrl = '/z2m-more++/c0mplex.url/';
|
||||
settings.set(['frontend'], {base_url: baseUrl});
|
||||
controller = new Controller(jest.fn(), jest.fn());
|
||||
await controller.start();
|
||||
|
||||
expect(ws.Server).toHaveBeenCalledWith({noServer: true, path: '/z2m-more++/c0mplex.url/api'});
|
||||
|
||||
mockHTTP.variables.onRequest({url: '/z2m-more++/c0mplex.url'}, 2);
|
||||
expect(mockNodeStatic.implementation).toHaveBeenCalledTimes(1);
|
||||
expect(mockNodeStatic.implementation).toHaveBeenCalledWith({originalUrl: '/z2m-more++/c0mplex.url', url: '/'}, 2, expect.any(Function));
|
||||
expect(mockFinalHandler.implementation).not.toHaveBeenCalledWith();
|
||||
|
||||
mockNodeStatic.implementation.mockReset();
|
||||
expect(mockFinalHandler.implementation).not.toHaveBeenCalledWith();
|
||||
mockHTTP.variables.onRequest({url: '/z2m-more++/c0mplex.url/file.txt'}, 2);
|
||||
expect(mockNodeStatic.implementation).toHaveBeenCalledTimes(1);
|
||||
expect(mockNodeStatic.implementation).toHaveBeenCalledWith(
|
||||
{originalUrl: '/z2m-more++/c0mplex.url/file.txt', url: '/file.txt'},
|
||||
2,
|
||||
expect.any(Function),
|
||||
);
|
||||
expect(mockFinalHandler.implementation).not.toHaveBeenCalledWith();
|
||||
|
||||
mockNodeStatic.implementation.mockReset();
|
||||
mockHTTP.variables.onRequest({url: '/z/file.txt'}, 2);
|
||||
expect(mockNodeStatic.implementation).not.toHaveBeenCalled();
|
||||
expect(mockFinalHandler.implementation).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -978,7 +978,7 @@ describe('Settings', () => {
|
||||
write(configurationFile, {...minimalConfig, frontend: true});
|
||||
|
||||
settings.reRead();
|
||||
expect(settings.get().frontend).toStrictEqual({port: 8080, auth_token: false});
|
||||
expect(settings.get().frontend).toStrictEqual({port: 8080, auth_token: null, base_url: '/'});
|
||||
});
|
||||
|
||||
it('Baudrate config', () => {
|
||||
|
||||
Reference in new issue
Block a user