Skip to content

Commit

Permalink
fix: add NotSet path for increase/decrease ttl apis
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta committed Oct 15, 2024
1 parent a96bf0a commit 4d30656
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/client-sdk-nodejs/src/internal/cache-data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4541,6 +4541,8 @@ export class CacheDataClient implements IDataClient {
(err, resp) => {
if (resp?.missing) {
resolve(new CacheIncreaseTtl.Miss());
} else if (resp?.not_set) {
resolve(new CacheIncreaseTtl.NotSet());
} else if (resp?.set) {
resolve(new CacheIncreaseTtl.Set());
} else {
Expand Down Expand Up @@ -4600,6 +4602,8 @@ export class CacheDataClient implements IDataClient {
(err, resp) => {
if (resp?.missing) {
resolve(new CacheDecreaseTtl.Miss());
} else if (resp?.not_set) {
resolve(new CacheDecreaseTtl.NotSet());
} else if (resp?.set) {
resolve(new CacheDecreaseTtl.Set());
} else {
Expand Down
4 changes: 4 additions & 0 deletions packages/client-sdk-web/src/internal/cache-data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4422,6 +4422,8 @@ export class CacheDataClient<
(err, resp) => {
if (resp?.getMissing()) {
resolve(new CacheIncreaseTtl.Miss());
} else if (resp?.getNotSet()) {
resolve(new CacheIncreaseTtl.NotSet());
} else if (resp?.getSet()) {
resolve(new CacheIncreaseTtl.Set());
} else {
Expand Down Expand Up @@ -4489,6 +4491,8 @@ export class CacheDataClient<
(err, resp) => {
if (resp?.getMissing()) {
resolve(new CacheDecreaseTtl.Miss());
} else if (resp?.getNotSet()) {
resolve(new CacheDecreaseTtl.NotSet());
} else if (resp?.getSet()) {
resolve(new CacheDecreaseTtl.Set());
} else {
Expand Down
12 changes: 6 additions & 6 deletions packages/common-integration-tests/src/cache/update-ttl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function runUpdateTtlTest(
expect(ttlResult.remainingTtlMillis()).toBeGreaterThan(15000);
});

it('should Error if given TTL is less than current TTL', async () => {
it('should NotSet for increaseTTL if given TTL is less than current TTL', async () => {
const cacheKey = v4();
await cacheClient.set(integrationTestCacheName, cacheKey, cacheKey, {
ttl: 10,
Expand All @@ -154,8 +154,8 @@ export function runUpdateTtlTest(
5000
);
expectWithMessage(() => {
expect(response).toBeInstanceOf(CacheIncreaseTtl.Error);
}, `expected ERROR but got ${response.toString()}`);
expect(response).toBeInstanceOf(CacheIncreaseTtl.NotSet);
}, `expected NOT_SET but got ${response.toString()}`);
});

it('should Error if given a TTL below 0', async () => {
Expand Down Expand Up @@ -241,7 +241,7 @@ export function runUpdateTtlTest(
expect(ttlResult.remainingTtlMillis()).toBeGreaterThan(0);
});

it('should Error if given TTL is greater than current TTL', async () => {
it('should NotSet for decreaseTTL if given TTL is greater than current TTL', async () => {
const cacheKey = v4();
await cacheClient.set(integrationTestCacheName, cacheKey, cacheKey, {
ttl: 10,
Expand All @@ -253,8 +253,8 @@ export function runUpdateTtlTest(
20000
);
expectWithMessage(() => {
expect(response).toBeInstanceOf(CacheDecreaseTtl.Error);
}, `expected ERROR but got ${response.toString()}`);
expect(response).toBeInstanceOf(CacheDecreaseTtl.NotSet);
}, `expected NOT_SET but got ${response.toString()}`);
});

it('should Error if given a TTL below 0', async () => {
Expand Down

0 comments on commit 4d30656

Please sign in to comment.