Skip to content

Commit

Permalink
Initial implementation with unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarehart committed Dec 10, 2023
1 parent b8f997d commit 2dbf717
Show file tree
Hide file tree
Showing 7 changed files with 579 additions and 76 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@

A wrapper around @aws-sdk/client-appconfigdata to provide background polling and caching.

## Usage

Initialize:

```typescript
const poller = new Poller({
dataClient: dataClient,
sessionConfig: {
ApplicationIdentifier: 'MyApp',
EnvironmentIdentifier: 'Test',
ConfigurationProfileIdentifier: 'Config1',
},
logger: console.log,
});

await poller.start();
```

Fetch:

```typescript
const value = poller.getConfigurationString().latestValue;
```

## License

Expand Down
42 changes: 0 additions & 42 deletions __tests__/main.test.ts

This file was deleted.

49 changes: 49 additions & 0 deletions __tests__/poller.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Poller } from '../src/poller.js';
import {
AppConfigDataClient,
GetLatestConfigurationCommand,
StartConfigurationSessionCommand,
} from '@aws-sdk/client-appconfigdata';
import { mockClient } from 'aws-sdk-client-mock';
import { Uint8ArrayBlobAdapter } from '@smithy/util-stream';

describe('Poller', () => {
const appConfigClientMock = mockClient(AppConfigDataClient);

const configValue = 'Some Configuration';

appConfigClientMock.on(StartConfigurationSessionCommand).resolves({
InitialConfigurationToken: 'initialToken',
});

appConfigClientMock.on(GetLatestConfigurationCommand).resolves({
Configuration: Uint8ArrayBlobAdapter.fromString(configValue),
});

const dataClient = new AppConfigDataClient();

let poller: Poller<string> | undefined;

afterAll(() => {
console.log('Stopping poller');
poller.stop();
});

it('Polls', async () => {
poller = new Poller({
dataClient: dataClient,
sessionConfig: {
ApplicationIdentifier: 'MyApp',
EnvironmentIdentifier: 'Test',
ConfigurationProfileIdentifier: 'Config1',
},
logger: console.log,
});

await poller.start();
const latest = poller.getConfigurationString();

expect(latest.latestValue).toEqual(configValue);
expect(latest.errorCausingStaleValue).toBeUndefined();
});
});
Loading

0 comments on commit 2dbf717

Please sign in to comment.