Skip to content

Commit

Permalink
Add integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iaj2 committed Nov 10, 2023
1 parent 44ff855 commit 6c16839
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/integration/PwmService.tests.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 6c16839

Please sign in to comment.