Skip to content

Commit

Permalink
add test to check that an action with same ID is not added to the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
VladBrok committed Aug 30, 2023
1 parent f5a86ac commit 6061995
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions server-client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,72 @@ it('undoes all other actions in a queue if error in one action occurs', async ()
expect(calls).toEqual(['GOOD 0', 'BAD'])
})

it('does not add action with same ID to the queue', async () => {
let app = createServer()
let errors: string[] = []
let calls: string[] = []
app.on('error', e => {
errors.push(e.message)
})
app.type(
'FOO',
{
access: () => true,
process: () => {
calls.push('FOO')
}
},
{ queue: '1' }
)
app.type(
'BAR',
{
access: () => true,
process: () => {
calls.push('BAR')
}
},
{ queue: '1' }
)
app.type(
'BAZ',
{
access: () => true,
process: () => {
calls.push('BAZ')
}
},
{ queue: '2' }
)
app.type(
'BOM',
{
access: () => true,
process: () => {
calls.push('BOM')
}
},
{ queue: '2' }
)

let client = await connectClient(app, '10:client:uuid')
await sendTo(client, [
'sync',
4,
{ type: 'FOO' },
{ id: [1, '10:client:other', 0], time: 1 },
{ type: 'BAR' },
{ id: [1, '10:client:other', 0], time: 1 },
{ type: 'BAZ' },
{ id: [1, '10:client:other', 0], time: 1 },
{ type: 'BOM' },
{ id: [2, '10:client:other', 0], time: 1 }
])

expect(errors).toEqual([])
expect(calls).toEqual(['FOO', 'BOM'])
})

it('does not undo actions in one queue if error occurs in another queue', async () => {
let app = createServer()
let calls: string[] = []
Expand Down

0 comments on commit 6061995

Please sign in to comment.