Skip to content

Commit

Permalink
Add onlyListed to CacheRouter.getSafeAppsCacheDir argument list (#1462)
Browse files Browse the repository at this point in the history
Adds `onlyListed` parameter to the `CacheDir` field when storing Safe Apps list in the cache.
  • Loading branch information
hectorgomezv authored Apr 26, 2024
1 parent df6e96e commit 809c07d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/datasources/cache/cache.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,12 @@ export class CacheRouter {
static getSafeAppsCacheDir(args: {
chainId?: string;
clientUrl?: string;
onlyListed?: boolean;
url?: string;
}): CacheDir {
return new CacheDir(
`${args.chainId}_${CacheRouter.SAFE_APPS_KEY}`,
`${args.clientUrl}_${args.url}`,
`${args.clientUrl}_${args.onlyListed}_${args.url}`,
);
}

Expand Down
20 changes: 16 additions & 4 deletions src/datasources/config-api/config-api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ describe('ConfigApi', () => {
expect(actual).toBe(data);
expect(mockDataSource.get).toHaveBeenCalledTimes(1);
expect(mockDataSource.get).toHaveBeenCalledWith({
cacheDir: new CacheDir(`${chainId}_safe_apps`, 'undefined_undefined'),
cacheDir: new CacheDir(
`${chainId}_safe_apps`,
'undefined_undefined_undefined',
),
url: `${baseUri}/api/v1/safe-apps/`,
notFoundExpireTimeSeconds: notFoundExpirationTimeInSeconds,
networkRequest: {
Expand All @@ -136,7 +139,10 @@ describe('ConfigApi', () => {
expect(actual).toBe(data);
expect(mockDataSource.get).toHaveBeenCalledTimes(1);
expect(mockDataSource.get).toHaveBeenCalledWith({
cacheDir: new CacheDir(`${chainId}_safe_apps`, `undefined_${url}`),
cacheDir: new CacheDir(
`${chainId}_safe_apps`,
`undefined_undefined_${url}`,
),
url: `${baseUri}/api/v1/safe-apps/`,
notFoundExpireTimeSeconds: notFoundExpirationTimeInSeconds,
networkRequest: { params: { chainId, clientUrl: undefined, url } },
Expand All @@ -156,7 +162,10 @@ describe('ConfigApi', () => {
expect(actual).toBe(data);
expect(mockDataSource.get).toHaveBeenCalledTimes(1);
expect(mockDataSource.get).toHaveBeenCalledWith({
cacheDir: new CacheDir(`${chainId}_safe_apps`, `${clientUrl}_undefined`),
cacheDir: new CacheDir(
`${chainId}_safe_apps`,
`${clientUrl}_undefined_undefined`,
),
url: `${baseUri}/api/v1/safe-apps/`,
notFoundExpireTimeSeconds: notFoundExpirationTimeInSeconds,
networkRequest: { params: { chainId, clientUrl, url: undefined } },
Expand All @@ -181,7 +190,10 @@ describe('ConfigApi', () => {
expect(actual).toBe(data);
expect(mockDataSource.get).toHaveBeenCalledTimes(1);
expect(mockDataSource.get).toHaveBeenCalledWith({
cacheDir: new CacheDir(`${chainId}_safe_apps`, `${clientUrl}_undefined`),
cacheDir: new CacheDir(
`${chainId}_safe_apps`,
`${clientUrl}_${onlyListed}_undefined`,
),
url: `${baseUri}/api/v1/safe-apps/`,
notFoundExpireTimeSeconds: notFoundExpirationTimeInSeconds,
networkRequest: {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/safe-apps/__tests__/get-safe-apps.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Get Safe Apps e2e test', () => {

it('GET /chains/<chainId>/safe-apps', async () => {
const safeAppsCacheKey = `${cacheKeyPrefix}-${chainId}_safe_apps`;
const safeAppsCacheField = 'undefined_undefined';
const safeAppsCacheField = 'undefined_true_undefined';

await request(app.getHttpServer())
.get(`/v1/chains/${chainId}/safe-apps`)
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Get Safe Apps e2e test', () => {
it('GET /chains/<chainId>/safe-apps?url=${transactionBuilderUrl}', async () => {
const safeAppsCacheKey = `${cacheKeyPrefix}-${chainId}_safe_apps`;
const transactionBuilderUrl = 'https://safe-apps.dev.5afe.dev/tx-builder';
const safeAppsCacheField = `undefined_${transactionBuilderUrl}`;
const safeAppsCacheField = `undefined_true_${transactionBuilderUrl}`;

await request(app.getHttpServer())
.get(`/v1/chains/${chainId}/safe-apps/?url=${transactionBuilderUrl}`)
Expand Down

0 comments on commit 809c07d

Please sign in to comment.