Skip to content

Commit

Permalink
fix: tcp/udp api not accepting button text or custom variable values …
Browse files Browse the repository at this point in the history
…containing slashes
  • Loading branch information
Julusian committed Dec 7, 2024
1 parent 3a772ab commit 2bce28b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
6 changes: 3 additions & 3 deletions companion/lib/Service/TcpUdpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class ServiceTcpUdpApi extends CoreBase {
if (!control.stepMakeCurrent(step)) throw new ApiMessageError('Step out of range')
})

this.#router.addPath('style bank :page :bank text{ :text}', (match) => {
this.#router.addPath('style bank :page :bank text{ *text}', (match) => {
this.#checkLegacyRouteAllowed()

const controlId = this.page.getControlIdAtOldBankIndex(Number(match.page), Number(match.bank))
Expand Down Expand Up @@ -247,15 +247,15 @@ export class ServiceTcpUdpApi extends CoreBase {
this.#router.addPath('location :page/:row/:column rotate-right', this.#locationRotateRight)
this.#router.addPath('location :page/:row/:column set-step :step', this.#locationSetStep)

this.#router.addPath('location :page/:row/:column style text{ :text}', this.#locationStyleText)
this.#router.addPath('location :page/:row/:column style text{ *text}', this.#locationStyleText)
this.#router.addPath('location :page/:row/:column style color :color', this.#locationStyleColor)
this.#router.addPath('location :page/:row/:column style bgcolor :bgcolor', this.#locationStyleBgcolor)

// surfaces
this.#router.addPath('surfaces rescan', this.#surfacesRescan)

// custom variables
this.#router.addPath('custom-variable :name set-value {:value}', this.#customVariableSetValue)
this.#router.addPath('custom-variable :name set-value {*value}', this.#customVariableSetValue)
}

/**
Expand Down
50 changes: 46 additions & 4 deletions companion/test/Service/TcpUdpApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,23 @@ describe('TcpUdpApi', () => {
mockFn.mockReturnValue(null)

// Perform the request
await router.processMessage('custom-variable my-var-name set-value 123')
await router.processMessage('custom-variable my-var-name set-value 123 def')

expect(mockFn).toHaveBeenCalledTimes(1)
expect(mockFn).toHaveBeenCalledWith('my-var-name', '123')
expect(mockFn).toHaveBeenCalledWith('my-var-name', '123 def')
})

test('ok from query with slash', async () => {
const { router, registry } = createService()

const mockFn = registry.variables.custom.setValue
mockFn.mockReturnValue(null)

// Perform the request
await router.processMessage('custom-variable my-var-name set-value 12/3 def')

expect(mockFn).toHaveBeenCalledTimes(1)
expect(mockFn).toHaveBeenCalledWith('my-var-name', '12/3 def')
})

test('ok empty', async () => {
Expand Down Expand Up @@ -638,7 +651,36 @@ describe('TcpUdpApi', () => {
registry.controls.getControl.mockReturnValue(mockControl)

// Perform the request
router.processMessage('location 1/2/3 style text def')
router.processMessage('location 1/2/3 style text def two')

expect(registry.page.getControlIdAt).toHaveBeenCalledTimes(1)
expect(registry.page.getControlIdAt).toHaveBeenCalledWith({
pageNumber: 1,
row: 2,
column: 3,
})

expect(registry.controls.getControl).toHaveBeenCalledTimes(1)
expect(registry.controls.getControl).toHaveBeenCalledWith('abc')

expect(mockControl.styleSetFields).toHaveBeenCalledTimes(1)
expect(mockControl.styleSetFields).toHaveBeenCalledWith({ text: 'def two' })
})

test('ok with slash', async () => {
const { router, registry } = createService()
registry.page.getControlIdAt.mockReturnValue('abc')

const mockControl = mock<ControlButtonNormal>(
{
styleSetFields: vi.fn(),
},
mockOptions
)
registry.controls.getControl.mockReturnValue(mockControl)

// Perform the request
router.processMessage('location 1/2/3 style text de/f two')

expect(registry.page.getControlIdAt).toHaveBeenCalledTimes(1)
expect(registry.page.getControlIdAt).toHaveBeenCalledWith({
Expand All @@ -651,7 +693,7 @@ describe('TcpUdpApi', () => {
expect(registry.controls.getControl).toHaveBeenCalledWith('abc')

expect(mockControl.styleSetFields).toHaveBeenCalledTimes(1)
expect(mockControl.styleSetFields).toHaveBeenCalledWith({ text: 'def' })
expect(mockControl.styleSetFields).toHaveBeenCalledWith({ text: 'de/f two' })
})

test('ok no text', async () => {
Expand Down

0 comments on commit 2bce28b

Please sign in to comment.