From 6c16839d0cd4a9e93acd596b893e3a25ffeaf366 Mon Sep 17 00:00:00 2001 From: iaj2 Date: Thu, 9 Nov 2023 16:14:09 -0800 Subject: [PATCH] Add integration tests. --- tests/integration/PwmService.tests.ts | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/integration/PwmService.tests.ts diff --git a/tests/integration/PwmService.tests.ts b/tests/integration/PwmService.tests.ts new file mode 100644 index 0000000..ddda740 --- /dev/null +++ b/tests/integration/PwmService.tests.ts @@ -0,0 +1,74 @@ +import { PWMService, Polarity } from "../../src" +import { PWMPin } from "../../src" + +jest.unmock('zeromq') + +describe('PwmService', () => { + let pwm: PWMService + + beforeAll(async () => { + pwm = new PWMService('tcp://localhost:5555'); + await pwm.initPwm(PWMPin.PWM1) + await pwm.initPwm(PWMPin.PWM2) + }) + + test.each([ + [{pwm_num: PWMPin.PWM1, polarity: Polarity.NORMAL}], + [{pwm_num: PWMPin.PWM2, polarity: Polarity.INVERSED}], + [{pwm_num: PWMPin.PWM1, frequency: 1000}], + [{pwm_num: PWMPin.PWM1, duty_cycle: 0}] + + ])('Call setConfig and check success message', async (args) => { + const response = await pwm.setConfig(args) + expect(response).toEqual('Successfully applied pwm configurations.') + }) + + + test.each([ + [PWMPin.PWM1], + [PWMPin.PWM2], + ])('Call enable and check success message', async (pwm_num) => { + const response = await pwm.enable(pwm_num) + expect(response).toEqual(`Successful enabled ${pwm_num}.`) + }) + + test.each([ + [PWMPin.PWM1], + [PWMPin.PWM2], + ])('Call disable and check success message', async (pwm_num) => { + const response = await pwm.disable(pwm_num) + expect(response).toEqual(`Successful disabled ${pwm_num}.`) + }) + + test.each([ + [PWMPin.PWM1], + [PWMPin.PWM2], + ])('Call close and check success message', async (pwm_num) => { + const response = await pwm.close(pwm_num) + expect(response).toEqual(`Successfully closed ${pwm_num}.`) + }) + + test.each([ + [PWMPin.PWM1], + [PWMPin.PWM2], + ])('Call getFrequency and check frequency type', async (pwm_num) => { + const frequency = await pwm.getFrequency(pwm_num) + expect(typeof frequency).toBe('number') + }) + + test.each([ + [PWMPin.PWM1], + [PWMPin.PWM2], + ])('Call getDutyCycle and duty cycle type', async (pwm_num) => { + const dutyCycle = await pwm.getDutyCycle(pwm_num) + expect(typeof dutyCycle).toBe('number') + }) + + test.each([ + [PWMPin.PWM1], + [PWMPin.PWM2], + ])('Call getPolarity and check polarity type', async (pwm_num) => { + const polarity = await pwm.getPolarity(pwm_num) + expect(Object.values(Polarity)).toContain(polarity) + }) +})