Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,74 @@ | ||
import Redis from 'ioredis' | ||
|
||
describe('hincrbyfloat', () => { | ||
it('should increment an float with passed increment', () => { | ||
const redis = new Redis({ | ||
data: { | ||
mykey: { field: '10.50' }, | ||
}, | ||
}) | ||
// eslint-disable-next-line import/no-relative-parent-imports | ||
import { runTwinSuite } from '../../../test-utils' | ||
|
||
return redis | ||
.hincrbyfloat('mykey', 'field', 0.1) | ||
.then(result => { | ||
return expect(result).toBe('10.6') | ||
}) | ||
.then(() => { | ||
return redis.hincrbyfloat('mykey', 'field', -5) | ||
}) | ||
.then(result => { | ||
return expect(result).toBe('5.6') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('mykey').field).toBe('5.6') | ||
runTwinSuite('hincrbyfloat', command => { | ||
describe(command, () => { | ||
it('should increment an float with passed increment', () => { | ||
const redis = new Redis({ | ||
data: { | ||
mykey: { field: '10.50' }, | ||
}, | ||
}) | ||
}) | ||
|
||
it('should support exponents', () => { | ||
const redis = new Redis({ | ||
data: { | ||
mykey: { field: '5.0e3' }, | ||
}, | ||
return redis[command]('mykey', 'field', 0.1) | ||
.then(result => { | ||
return expect(result).toBe('10.6') | ||
}) | ||
.then(() => { | ||
return redis[command]('mykey', 'field', -5) | ||
}) | ||
.then(result => { | ||
return expect(result).toBe('5.6') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('mykey').field).toBe('5.6') | ||
}) | ||
}) | ||
|
||
return redis | ||
.hincrbyfloat('mykey', 'field', '2.0e2') | ||
.then(result => { | ||
return expect(result).toBe('5200') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('mykey').field).toBe('5200') | ||
it('should support exponents', () => { | ||
const redis = new Redis({ | ||
data: { | ||
mykey: { field: '5.0e3' }, | ||
}, | ||
}) | ||
}) | ||
|
||
it('should create hash if not exists', () => { | ||
const redis = new Redis() | ||
return redis[command]('mykey', 'field', '2.0e2') | ||
.then(result => { | ||
return expect(result).toBe('5200') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('mykey').field).toBe('5200') | ||
}) | ||
}) | ||
|
||
return redis | ||
.hincrbyfloat('stats', 'health', 0.5) | ||
.then(result => { | ||
return expect(result).toBe('0.5') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('stats').health).toBe('0.5') | ||
}) | ||
}) | ||
it('should create hash if not exists', () => { | ||
const redis = new Redis() | ||
|
||
it('should create field in hash if not exists', () => { | ||
const redis = new Redis({ | ||
data: { | ||
stats: {}, | ||
}, | ||
return redis[command]('stats', 'health', 0.5) | ||
.then(result => { | ||
return expect(result).toBe('0.5') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('stats').health).toBe('0.5') | ||
}) | ||
}) | ||
|
||
return redis | ||
.hincrbyfloat('stats', 'health', 0.5) | ||
.then(result => { | ||
return expect(result).toBe('0.5') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('stats').health).toBe('0.5') | ||
it('should create field in hash if not exists', () => { | ||
const redis = new Redis({ | ||
data: { | ||
stats: {}, | ||
}, | ||
}) | ||
|
||
return redis[command]('stats', 'health', 0.5) | ||
.then(result => { | ||
return expect(result).toBe('0.5') | ||
}) | ||
.then(() => { | ||
return expect(redis.data.get('stats').health).toBe('0.5') | ||
}) | ||
}) | ||
}) | ||
}) |