-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add basic integration tests for scalar and sorted set (#14)
Adds integration tests for scalar set and sorted set put elements.
- Loading branch information
Showing
3 changed files
with
119 additions
and
8 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,44 @@ | ||
import {v4} from 'uuid'; | ||
import {SetupIntegrationTest} from './integration-setup'; | ||
import {MultiRegionCacheSetResponse} from '../src'; | ||
import {CacheGetResponse} from '@gomomento/sdk'; | ||
|
||
const {multiRegionClient, regionalClients, cacheName} = SetupIntegrationTest(); | ||
|
||
describe('simple get and set', () => { | ||
it('happy path set get', async () => { | ||
const key = v4(); | ||
const value = v4(); | ||
|
||
const multiRegionSetResponse = await multiRegionClient.set( | ||
cacheName, | ||
key, | ||
value | ||
); | ||
|
||
expect(multiRegionSetResponse.type).toEqual( | ||
MultiRegionCacheSetResponse.Success | ||
); | ||
|
||
for (const [_, client] of Object.entries(regionalClients)) { | ||
const getResponse = await client.get(cacheName, key); | ||
expect(getResponse.type).toEqual(CacheGetResponse.Hit); | ||
expect(getResponse.value()).toEqual(value); | ||
} | ||
}); | ||
it("has an error when writing to a cache that doesn't exist", async () => { | ||
const key = v4(); | ||
const value = v4(); | ||
const nonExistentCacheName = v4(); | ||
|
||
const multiRegionSetResponse = await multiRegionClient.set( | ||
nonExistentCacheName, | ||
key, | ||
value | ||
); | ||
|
||
expect(multiRegionSetResponse.type).toEqual( | ||
MultiRegionCacheSetResponse.Error | ||
); | ||
}); | ||
}); |
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,51 @@ | ||
import {v4} from 'uuid'; | ||
import {SetupIntegrationTest} from './integration-setup'; | ||
import {MultiRegionCacheSortedSetPutElementsResponse} from '../src'; | ||
import {CacheSortedSetFetchResponse} from '@gomomento/sdk'; | ||
|
||
const {multiRegionClient, regionalClients, cacheName} = SetupIntegrationTest(); | ||
|
||
describe('sorted set put elements', () => { | ||
it('happy path put elements', async () => { | ||
const sortedSetName = v4(); | ||
|
||
const items = {element1: 1, element2: 2}; | ||
const multiRegionSetResponse = await multiRegionClient.sortedSetPutElements( | ||
cacheName, | ||
sortedSetName, | ||
items | ||
); | ||
|
||
expect(multiRegionSetResponse.type).toEqual( | ||
MultiRegionCacheSortedSetPutElementsResponse.Success | ||
); | ||
|
||
const expectedItems = Object.entries(items).map(([value, score]) => ({ | ||
value, | ||
score, | ||
})); | ||
for (const [_, client] of Object.entries(regionalClients)) { | ||
const getResponse = await client.sortedSetFetchByRank( | ||
cacheName, | ||
sortedSetName | ||
); | ||
expect(getResponse.type).toEqual(CacheSortedSetFetchResponse.Hit); | ||
expect(getResponse.value()).toEqual(expectedItems); | ||
} | ||
}); | ||
it("has an error when writing to a cache that doesn't exist", async () => { | ||
const sortedSetName = v4(); | ||
const items = {element1: 1, element2: 2}; | ||
const nonExistentCacheName = v4(); | ||
|
||
const multiRegionSetResponse = await multiRegionClient.sortedSetPutElements( | ||
nonExistentCacheName, | ||
sortedSetName, | ||
items | ||
); | ||
|
||
expect(multiRegionSetResponse.type).toEqual( | ||
MultiRegionCacheSortedSetPutElementsResponse.Error | ||
); | ||
}); | ||
}); |