Skip to content

Commit

Permalink
use updated folder name (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
dferber90 committed Oct 27, 2022
1 parent 98cc87d commit 99ac8af
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-cycles-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/edge-config': patch
---

access edge config via renamed folder
46 changes: 43 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,29 +430,44 @@ describe('createEdgeConfig', () => {
items: { foo: 'bar', someArray: [] },
};

beforeAll(() => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
let fs: typeof import('fs/promises');

beforeAll(async () => {
process.env.AWS_LAMBDA_FUNCTION_NAME = 'some-value';

// mock fs for test
jest.mock('fs/promises', () => {
return {
readFile: (): Promise<string> => {
readFile: jest.fn((): Promise<string> => {
return Promise.resolve(JSON.stringify(embeddedEdgeConfig));
},
}),
};
});

// eslint-disable-next-line unicorn/prefer-node-protocol
fs = await import('fs/promises');
});

afterAll(() => {
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
});

beforeEach(() => {
(fs.readFile as jest.Mock).mockClear();
});

describe('get(key)', () => {
describe('when item exists', () => {
it('should return the value', async () => {
const edgeConfig = createEdgeConfigClient(connectionString);
await expect(edgeConfig.get('foo')).resolves.toEqual('bar');
expect(fetchMock).toHaveBeenCalledTimes(0);
expect(fs.readFile).toHaveBeenCalledTimes(1);
expect(fs.readFile).toHaveBeenCalledWith(
'/opt/edge-config/ecfg-1.json',
'utf-8',
);
});

it('should not be able to modify the value for the next get', async () => {
Expand All @@ -465,6 +480,11 @@ describe('createEdgeConfig', () => {
// next get
await expect(edgeConfig.get('someArray')).resolves.toEqual([]);
expect(fetchMock).toHaveBeenCalledTimes(0);
expect(fs.readFile).toHaveBeenCalledTimes(1);
expect(fs.readFile).toHaveBeenCalledWith(
'/opt/edge-config/ecfg-1.json',
'utf-8',
);
});
});

Expand All @@ -473,6 +493,11 @@ describe('createEdgeConfig', () => {
const edgeConfig = createEdgeConfigClient(connectionString);
await expect(edgeConfig.get('baz')).resolves.toEqual(undefined);
expect(fetchMock).toHaveBeenCalledTimes(0);
expect(fs.readFile).toHaveBeenCalledTimes(1);
expect(fs.readFile).toHaveBeenCalledWith(
'/opt/edge-config/ecfg-1.json',
'utf-8',
);
});
});
});
Expand All @@ -483,6 +508,11 @@ describe('createEdgeConfig', () => {
const edgeConfig = createEdgeConfigClient(connectionString);
await expect(edgeConfig.has('foo')).resolves.toEqual(true);
expect(fetchMock).toHaveBeenCalledTimes(0);
expect(fs.readFile).toHaveBeenCalledTimes(1);
expect(fs.readFile).toHaveBeenCalledWith(
'/opt/edge-config/ecfg-1.json',
'utf-8',
);
});
});

Expand All @@ -491,6 +521,11 @@ describe('createEdgeConfig', () => {
const edgeConfig = createEdgeConfigClient(connectionString);
await expect(edgeConfig.has('baz')).resolves.toEqual(false);
expect(fetchMock).toHaveBeenCalledTimes(0);
expect(fs.readFile).toHaveBeenCalledTimes(1);
expect(fs.readFile).toHaveBeenCalledWith(
'/opt/edge-config/ecfg-1.json',
'utf-8',
);
});
});
});
Expand All @@ -500,6 +535,11 @@ describe('createEdgeConfig', () => {
const edgeConfig = createEdgeConfigClient(connectionString);
await expect(edgeConfig.digest()).resolves.toEqual('awe1');
expect(fetchMock).toHaveBeenCalledTimes(0);
expect(fs.readFile).toHaveBeenCalledTimes(1);
expect(fs.readFile).toHaveBeenCalledWith(
'/opt/edge-config/ecfg-1.json',
'utf-8',
);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function getLocalEdgeConfig(

try {
const content = await fs.readFile(
`/opt/edge-configs/${edgeConfigId}.json`,
`/opt/edge-config/${edgeConfigId}.json`,
'utf-8',
);
return JSON.parse(content) as EmbeddedEdgeConfig;
Expand Down

0 comments on commit 99ac8af

Please sign in to comment.