Skip to content

Commit

Permalink
Add unit test to validate fix for #875
Browse files Browse the repository at this point in the history
  • Loading branch information
BavoLuysterborg committed Dec 18, 2023
1 parent 4ab74af commit fe22c07
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions test/tools/auth0/handlers/logStreams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ const mockLogStreams = [
httpEndpoint: 'https://suspended.com/logs',
},
},
{
id: 'log-stream-5',
name: 'Active EventGrid Log Stream',
type: 'eventgrid',
status: 'active',
sink: {
azureSubscriptionId: 'some id',
azureRegion: 'some region',
azureResourceGroup: 'some rg',
azurePartnerTopic: 'some topic name',
},
},
{
id: 'log-stream-6',
name: 'Active EventBridge Log Stream',
type: 'eventbridge',
status: 'active',
sink: {
awsRegion: "some region",
awsAccountId: "some id",
awsPartnerEventSource: "some source",
},
},
];

const auth0ApiClientMock = {
Expand Down Expand Up @@ -119,10 +142,71 @@ describe('#logStreams handler', () => {
httpEndpoint: 'https://suspended.com/logs',
},
},
{
id: 'log-stream-5',
name: 'Active EventGrid Log Stream',
type: 'eventgrid',
status: 'active',
sink: {
azureSubscriptionId: 'some id',
azureRegion: 'some region',
azureResourceGroup: 'some rg',
azurePartnerTopic: 'some topic name',
},
},
{
id: 'log-stream-6',
name: 'Active EventBridge Log Stream',
type: 'eventbridge',
status: 'active',
sink: {
awsRegion: "some region",
awsAccountId: "some id",
awsPartnerEventSource: "some source",
},
},
],
});
});

it('should create log streams', async () => {
let didCreateFunctionGetCalled = false;

const handler = new logStreamsHandler({
config: () => {},
client: {
...auth0ApiClientMock,
logStreams: {
...auth0ApiClientMock.logStreams,
getAll: async () => [],
},
},
functions: {
create: (data) => {
didCreateFunctionGetCalled = true;
const expectedValue = (() => {
const value = mockLogStreams.find((logStream) => {
return logStream.id === data.id;
});
value.sink = { ...value.sink };
//@ts-ignore because it's actually ok for sink property to be omitted in POST payload
delete value.status; // Not expecting status in POST payload
if (value?.type == 'eventgrid') delete value.sink.azurePartnerTopic; // Topic name is auto-generated on create, not expecting it in POST payload
if (value?.type == 'eventbridge') delete value.sink.awsPartnerEventSource; // Not expecting this in POST payload

return value;
})();

expect(data).to.deep.equal(expectedValue);
return Promise.resolve(data);
},
},
});

await handler.processChanges({ logStreams: mockLogStreams });
expect(didCreateFunctionGetCalled).to.equal(true);
});

it('should update log streams settings', async () => {
let didUpdateFunctionGetCalled = false;

Expand All @@ -136,10 +220,13 @@ describe('#logStreams handler', () => {
const value = mockLogStreams.find((logStream) => {
return logStream.id === id;
});
//@ts-ignore because it's actually ok for status property to be omitted in PATCH payload
if (value?.type === 'eventbridge' || value?.type === 'eventgrid') delete value.sink;
delete value.id; // Not expecting ID in PATCH payload
delete value.type; // Not expecting type in PATCH payload
//@ts-ignore because it's actually ok for status property to be omitted in PATCH payload
if (value?.status === 'suspended') delete value.status; // Not expecting status in PATCH payload if suspended

return value;
})();

Expand Down

0 comments on commit fe22c07

Please sign in to comment.