Skip to content

Commit

Permalink
Release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Nov 26, 2024
1 parent f4afc73 commit f97a99a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('TestPlatform', () => {
let mockMatterbridge: Matterbridge;
let mockLog: AnsiLogger;
let mockConfig: PlatformConfig;
let testPlatform: ExampleMatterbridgeDynamicPlatform;
let dynamicPlatform: ExampleMatterbridgeDynamicPlatform;

let consoleLogSpy: jest.SpiedFunction<typeof console.log>;
let loggerLogSpy: jest.SpiedFunction<(level: LogLevel, message: string, ...parameters: any[]) => void>;
Expand Down Expand Up @@ -103,40 +103,40 @@ describe('TestPlatform', () => {
});

it('should initialize platform with config name', () => {
testPlatform = new ExampleMatterbridgeDynamicPlatform(mockMatterbridge, mockLog, mockConfig);
dynamicPlatform = new ExampleMatterbridgeDynamicPlatform(mockMatterbridge, mockLog, mockConfig);
expect(mockLog.info).toHaveBeenCalledWith('Initializing platform:', mockConfig.name);
});

it('should call onStart in edge mode', async () => {
mockMatterbridge.edge = true;
await testPlatform.onStart('Test reason');
await dynamicPlatform.onStart('Test reason');
expect(mockLog.info).toHaveBeenCalledWith('onStart called with reason:', 'Test reason');
}, 60000);

it('should call onConfigure in edge mode', async () => {
jest.useFakeTimers();

await testPlatform.onConfigure();
await dynamicPlatform.onConfigure();
expect(mockLog.info).toHaveBeenCalledWith('onConfigure called');

jest.advanceTimersByTime(60 * 1000);
jest.useRealTimers();
});

it('should call onShutdown in edge mode', async () => {
await testPlatform.onShutdown('Test reason');
await dynamicPlatform.onShutdown('Test reason');
expect(mockLog.info).toHaveBeenCalledWith('onShutdown called with reason:', 'Test reason');
mockMatterbridge.edge = false;
});

it('should call onStart with reason', async () => {
await testPlatform.onStart('Test reason');
await dynamicPlatform.onStart('Test reason');
expect(mockLog.info).toHaveBeenCalledWith('onStart called with reason:', 'Test reason');
}, 60000);

it('should execute the commandHandlers', async () => {
// Invoke command handlers
for (const [key, device] of Array.from(testPlatform.bridgedDevices)) {
for (const [key, device] of Array.from(dynamicPlatform.bridgedDevices)) {
const identify = device.getClusterServer(IdentifyCluster);
expect(identify).toBeDefined();
if (identify) await invokeCommands(identify as unknown as ClusterServerObj);
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('TestPlatform', () => {
it('should call onConfigure', async () => {
jest.useFakeTimers();

await testPlatform.onConfigure();
await dynamicPlatform.onConfigure();
expect(mockLog.info).toHaveBeenCalledWith('onConfigure called');

// Simulate multiple interval executions
Expand All @@ -227,7 +227,7 @@ describe('TestPlatform', () => {
}, 60000);

it('should call onShutdown with reason', async () => {
await testPlatform.onShutdown('Test reason');
await dynamicPlatform.onShutdown('Test reason');
expect(mockLog.info).toHaveBeenCalledWith('onShutdown called with reason:', 'Test reason');
});
});

0 comments on commit f97a99a

Please sign in to comment.