-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
6bd5b7b
commit 6020f4b
Showing
3 changed files
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {SetupIntegrationTest} from './integration-setup'; | ||
import {v4} from 'uuid'; | ||
|
||
const {client} = SetupIntegrationTest(); | ||
|
||
describe('increment', () => { | ||
it('should increment the value of the key by 1 if the key exists', async () => { | ||
const key = v4(); | ||
const value = 5; | ||
|
||
// Set initial key value | ||
await client.set(key, value); | ||
|
||
// Increment the value of the key | ||
const incrResp = await client.incr(key); | ||
expect(incrResp).toBe(value + 1); | ||
}); | ||
|
||
it('should increment the value of the key to 1 if the key does not exists', async () => { | ||
const key = v4(); | ||
|
||
// Increment the value of the key that is not set | ||
const incrResp = await client.incr(key); | ||
expect(incrResp).toBe(1); | ||
}); | ||
|
||
it('should error out if the key contains a value of wrong type or contains a string that can be represented as integer', async () => { | ||
const key = v4(); | ||
const value = 'monkey'; | ||
|
||
// Set initial key value | ||
await client.set(key, value); | ||
|
||
// Increment the value of the key that is not set | ||
try { | ||
await client.incr(key); | ||
} catch (error) { | ||
if (process.env.MOMENTO_ENABLED === 'true') { | ||
const momentoError = error as { | ||
code: string; | ||
context: {code: string; msg: string; op: string; platform: string}; | ||
}; | ||
expect(momentoError.code).toBe('ERR_UNHANDLED_ERROR'); | ||
expect(momentoError.context.code).toBe('FAILED_PRECONDITION_ERROR'); | ||
expect(momentoError.context.msg).toBe( | ||
"System is not in a state required for the operation's execution: 9 FAILED_PRECONDITION: failed to parse value into long" | ||
); | ||
expect(momentoError.context.op).toBe('incr'); | ||
expect(momentoError.context.platform).toBe('momento'); | ||
} else { | ||
expect(error).toBeInstanceOf(Error); | ||
expect((error as Error).message).toBe( | ||
'ERR value is not an integer or out of range' | ||
); | ||
} | ||
} | ||
}); | ||
|
||
it('should increment the value of key that contains a string that can be represented as integer', async () => { | ||
const key = v4(); | ||
const value = '10'; | ||
|
||
// Set initial key value | ||
await client.set(key, value); | ||
|
||
// Increment the value of the key that is not set | ||
const incrResp = await client.incr(key); | ||
expect(incrResp).toBe(11); | ||
}); | ||
}); |
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