Skip to content

Commit

Permalink
fix typos, clarify setPop description, adds length check to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anitarua committed Aug 8, 2024
1 parent c46016e commit c45d435
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
45 changes: 36 additions & 9 deletions packages/common-integration-tests/src/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export function runSetTests(
it('should return MISS if set does not exist', async () => {
const noKeyGetResponse = await cacheClient.setFetch(
integrationTestCacheName,
'this-set-doesnt-exist'
v4()
);
expect(noKeyGetResponse).toBeInstanceOf(CacheSetFetch.Miss);
});
Expand Down Expand Up @@ -777,7 +777,7 @@ export function runSetTests(
it('validates limit', async () => {
const response = await cacheClient.setSample(
integrationTestCacheName,
'this-set-doesnt-exist',
v4(),
-1
);
expectWithMessage(() => {
Expand All @@ -791,7 +791,7 @@ export function runSetTests(
it('should return MISS if set does not exist', async () => {
const response = await cacheClient.setSample(
integrationTestCacheName,
'this-set-doesnt-exist',
v4(),
10
);
expectWithMessage(() => {
Expand Down Expand Up @@ -928,7 +928,7 @@ export function runSetTests(
it('validates count', async () => {
const negativeResponse = await cacheClient.setPop(
integrationTestCacheName,
'this-set-doesnt-exist',
v4(),
-1
);
expectWithMessage(() => {
Expand All @@ -940,7 +940,7 @@ export function runSetTests(

const zeroResponse = await cacheClient.setPop(
integrationTestCacheName,
'this-set-doesnt-exist',
v4(),
0
);
expectWithMessage(() => {
Expand All @@ -954,7 +954,7 @@ export function runSetTests(
it('should return MISS if set does not exist', async () => {
const response = await cacheClient.setPop(
integrationTestCacheName,
'this-set-doesnt-exist',
v4(),
10
);
expectWithMessage(() => {
Expand Down Expand Up @@ -994,6 +994,15 @@ export function runSetTests(
for (const value of valuesArrayLess) {
expect(elements).toContain(value);
}

const lengthResponse = await cacheClient.setLength(
integrationTestCacheName,
setName
);
expectWithMessage(() => {
expect(lengthResponse).toBeInstanceOf(CacheSetLength.Hit);
}, `expected HIT but got ${lengthResponse.toString()}`);
expect((lengthResponse as CacheSetLength.Hit).length()).toEqual(2);
});

it('should return HIT when set exists - count == set size', async () => {
Expand Down Expand Up @@ -1028,6 +1037,15 @@ export function runSetTests(
for (const value of valuesArrayEqual) {
expect(elements).toContain(value);
}

const lengthResponse = await cacheClient.setLength(
integrationTestCacheName,
setName
);
expectWithMessage(() => {
expect(lengthResponse).toBeInstanceOf(CacheSetLength.Hit);
}, `expected HIT but got ${lengthResponse.toString()}`);
expect((lengthResponse as CacheSetLength.Hit).length()).toEqual(0);
});

it('should return HIT when set exists - count > set size', async () => {
Expand Down Expand Up @@ -1062,9 +1080,18 @@ export function runSetTests(
for (const value of valuesArrayMore) {
expect(elements).toContain(value);
}

const lengthResponse = await cacheClient.setLength(
integrationTestCacheName,
setName
);
expectWithMessage(() => {
expect(lengthResponse).toBeInstanceOf(CacheSetLength.Hit);
}, `expected HIT but got ${lengthResponse.toString()}`);
expect((lengthResponse as CacheSetLength.Hit).length()).toEqual(0);
});

it('should support happy path for fetch via curried cache via ICache interface', async () => {
it('should support happy path for setPop via curried cache via ICache interface', async () => {
const setName = v4();

const cache = cacheClient.cache(integrationTestCacheName);
Expand Down Expand Up @@ -1118,7 +1145,7 @@ export function runSetTests(
it('should return MISS if set does not exist', async () => {
const response = await cacheClient.setLength(
integrationTestCacheName,
'this-set-doesnt-exist'
v4()
);
expectWithMessage(() => {
expect(response).toBeInstanceOf(CacheSetLength.Miss);
Expand Down Expand Up @@ -1156,7 +1183,7 @@ export function runSetTests(
);
});

it('should support happy path for fetch via curried cache via ICache interface', async () => {
it('should support happy path for setLength via curried cache via ICache interface', async () => {
const setName = v4();

const cache = cacheClient.cache(integrationTestCacheName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,7 @@ export abstract class AbstractCacheClient implements ICacheClient {
}

/**
* Fetch and remove a random sample of elements from the set.
* Returns a different random sample for each call.
* Pops a random sample of elements from the set.
*
* @param {string} cacheName - The cache containing the set.
* @param {string} setName - The set to remove from.
Expand Down

0 comments on commit c45d435

Please sign in to comment.