Skip to content

Commit

Permalink
chore: make cache optional (#193)
Browse files Browse the repository at this point in the history
* fix: do not process if cache is not configured

* fix: fix test to not fail if cache credentials are missing
  • Loading branch information
wa0x6e authored Oct 2, 2023
1 parent 4dcdf7a commit 77dfe85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export async function get(key) {
}

export async function remove(key) {
if (!client) return false;
try {
return await client.deleteObject({
Bucket: process.env.AWS_BUCKET_NAME,
Expand Down
42 changes: 25 additions & 17 deletions test/e2e/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,36 @@ describe('GET /ipfs/:cid', () => {
});

describe('when the file is cached', () => {
const cachedContent = { status: 'CACHED' };
if (process.env.AWS_REGION) {
const cachedContent = { status: 'CACHED' };

it('returns the cache file', async () => {
await set(cid, cachedContent);
const response = await request(HOST).get(path);
it('returns the cache file', async () => {
await set(cid, cachedContent);
const response = await request(HOST).get(path);

expect(response.body).toEqual(cachedContent);
expect(response.statusCode).toBe(200);
expect(response.headers['content-type']).toBe('application/json; charset=utf-8');
expect(await get(cid)).toEqual(cachedContent);
});
expect(response.body).toEqual(cachedContent);
expect(response.statusCode).toBe(200);
expect(response.headers['content-type']).toBe('application/json; charset=utf-8');
expect(await get(cid)).toEqual(cachedContent);
});
} else {
it.todo('needs to set AWS credentials to test the cache');
}
});

describe('when the file is not cached', () => {
it('returns the file and caches it', async () => {
const response = await request(HOST).get(path);

expect(response.body).toEqual(content);
expect(response.statusCode).toBe(200);
expect(response.headers['content-type']).toBe('application/json; charset=utf-8');
expect(await get(cid)).toEqual(response.body);
});
if (process.env.AWS_REGION) {
it('returns the file and caches it', async () => {
const response = await request(HOST).get(path);

expect(response.body).toEqual(content);
expect(response.statusCode).toBe(200);
expect(response.headers['content-type']).toBe('application/json; charset=utf-8');
expect(await get(cid)).toEqual(response.body);
});
} else {
it.todo('needs to set AWS credentials to test the cache');
}
});

it('returns a 415 error when not a JSON file', async () => {
Expand Down

0 comments on commit 77dfe85

Please sign in to comment.