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 f5fdb9a commit f43a7d4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Docker Version](https://img.shields.io/docker/v/luligu/matterbridge?label=docker%20version&sort=semver)](https://hub.docker.com/r/luligu/matterbridge)
[![Docker Pulls](https://img.shields.io/docker/pulls/luligu/matterbridge.svg)](https://hub.docker.com/r/luligu/matterbridge)
![Node.js CI](https://github.com/Luligu/matterbridge-example-accessory-platform/actions/workflows/build-matterbridge-plugin.yml/badge.svg)
![Coverage](https://img.shields.io/badge/Jest%20coverage-97.95%25-brightgreen)
![Coverage](https://img.shields.io/badge/Jest%20coverage-100%25-brightgreen)

[![power by](https://img.shields.io/badge/powered%20by-matterbridge-blue)](https://www.npmjs.com/package/matterbridge)
[![power by](https://img.shields.io/badge/powered%20by-matter--history-blue)](https://www.npmjs.com/package/matter-history)
Expand Down
41 changes: 37 additions & 4 deletions src/platform.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ClusterServerObj, IdentifyCluster, Matterbridge, PlatformConfig, WindowCovering, WindowCoveringCluster } from 'matterbridge';
import { ClusterServerObj, IdentifyCluster, Matterbridge, MatterbridgeDevice, MatterbridgeEndpoint, PlatformConfig, WindowCovering, WindowCoveringCluster } from 'matterbridge';
import { AnsiLogger, LogLevel, TimestampFormat } from 'matterbridge/logger';
import { ExampleMatterbridgeAccessoryPlatform } from './platform';
import { jest } from '@jest/globals';
import { wait } from 'matterbridge/utils';

describe('TestPlatform', () => {
let mockMatterbridge: Matterbridge;
Expand Down Expand Up @@ -31,9 +32,15 @@ describe('TestPlatform', () => {
}
}

beforeAll(() => {
beforeAll(async () => {
mockMatterbridge = {
addBridgedDevice: jest.fn(),
addBridgedDevice: jest.fn(async (pluginName: string, device: MatterbridgeDevice) => {
// console.error('addBridgedDevice called');
}),
addBridgedEndpoint: jest.fn(async (pluginName: string, device: MatterbridgeEndpoint) => {
device.number = 100;
// console.error('addBridgedEndpoint called');
}),
matterbridgeDirectory: '',
matterbridgePluginDirectory: 'temp',
systemInformation: { ipv4Address: undefined },
Expand Down Expand Up @@ -68,6 +75,11 @@ describe('TestPlatform', () => {
consoleLogSpy.mockRestore();
});

afterEach(async () => {
if (accessoryPlatform) await accessoryPlatform.onShutdown('Test reason');
jest.clearAllTimers();
});

it('should initialize platform with config name', () => {
accessoryPlatform = new ExampleMatterbridgeAccessoryPlatform(mockMatterbridge, mockLog, mockConfig);
expect(mockLog.info).toHaveBeenCalledWith('Initializing platform:', mockConfig.name);
Expand All @@ -81,6 +93,28 @@ describe('TestPlatform', () => {
mockMatterbridge.matterbridgeVersion = '1.6.2';
});

it('should call onStart in edge mode', async () => {
mockMatterbridge.edge = true;
await accessoryPlatform.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 accessoryPlatform.onConfigure();
expect(mockLog.info).toHaveBeenCalledWith('onConfigure called');

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

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

it('should call onStart with reason', async () => {
await accessoryPlatform.onStart('Test reason');
expect(mockLog.info).toHaveBeenCalledWith('onStart called with reason:', 'Test reason');
Expand Down Expand Up @@ -117,7 +151,6 @@ describe('TestPlatform', () => {
expect(mockLog.info).toHaveBeenCalledWith('onConfigure called');

jest.advanceTimersByTime(60 * 1000);

jest.useRealTimers();
});

Expand Down

0 comments on commit f43a7d4

Please sign in to comment.