Skip to content

Commit

Permalink
fix(del): throws if wrong number of args
Browse files Browse the repository at this point in the history
closes #1168
  • Loading branch information
stipsan committed May 4, 2022
1 parent 9b3b6f7 commit ac35d50
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/commands/del.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { emitNotification } from '../keyspace-notifications'

export function del(...keys) {
if (keys.length === 0 || !keys[0]) {
throw new Error("ERR wrong number of arguments for 'del' command")
}

let deleted = 0
keys.forEach(key => {
if (this.data.has(key)) {
Expand Down
5 changes: 5 additions & 0 deletions test/integration/commands/__snapshots__/del.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`del throws if too few arguments 1`] = `"ERR wrong number of arguments for 'del' command"`;

exports[`delBuffer throws if too few arguments 1`] = `"ERR wrong number of arguments for 'del' command"`;
21 changes: 17 additions & 4 deletions test/integration/commands/del.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@ import { runTwinSuite } from '../../../test-utils'

runTwinSuite('del', command => {
describe(command, () => {
const redis = new Redis()

afterAll(() => redis.disconnect())

it('should delete passed in keys', async () => {
const redis = new Redis()
await redis.set('deleteme', 'please')
await redis.set('metoo', 'pretty please')

expect(await redis[command]('deleteme', 'metoo')).toBe(2)
expect(await redis.get('deleteme')).toBe(null)
expect(await redis.get('metoo')).toBe(null)
redis.disconnect()
})
it('return 0 if nothing is deleted', async () => {
const redis = new Redis()
expect(await redis[command]('deleteme', 'metoo')).toBe(0)
})

it('return 0 if nothing is deleted', async () => {
expect(await redis[command]('deleteme', 'metoo')).toBe(0)
redis.disconnect()
})

it('throws if too few arguments', async () => {
expect.assertions(1)

try {
await redis[command]()
} catch (err) {
expect(err.message).toMatchSnapshot()
}
})
})
})

0 comments on commit ac35d50

Please sign in to comment.