-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from deven-org/develop
Develop
- Loading branch information
Showing
21 changed files
with
958 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,99 @@ | ||
import * as moduleAddSignature from "../core/addSignature"; | ||
import * as moduleCollectMetrics from "../core/collectMetrics"; | ||
import * as moduleStoreData from "../core/storeData"; | ||
import { handler } from "../handler"; | ||
import mergedCompletedSuccessfully from "./fixtures/merged-completed-successful.json"; | ||
import { logger } from "../core/logger"; | ||
import { DataEventSignature } from "../interfaces"; | ||
import { LogErrors, LogWarnings } from "../shared/logMessages"; | ||
|
||
describe("Handler", () => { | ||
beforeEach(() => {}); | ||
jest.mock("../core/logger", () => ({ | ||
__esModule: true, | ||
logger: { | ||
start: jest.fn(), | ||
config: jest.fn(), | ||
info: jest.fn(), | ||
warning: jest.fn(), | ||
error: jest.fn(), | ||
complete: jest.fn(), | ||
}, | ||
})); | ||
|
||
afterEach(() => {}); | ||
const spyOnAddSignature = jest.spyOn(moduleAddSignature, "addSignature"); | ||
const spyOnCollectMetrics = jest.spyOn(moduleCollectMetrics, "collectMetrics"); | ||
const spyOnStoreData = jest.spyOn(moduleCollectMetrics, "collectMetrics"); | ||
|
||
it.only("returns the payload enhanced with relative matrix", async () => { | ||
const data = { | ||
signature: "packages", | ||
describe("handler", () => { | ||
it("calls addSignature passing the given event payload", async () => { | ||
const event = { | ||
foo: "foo", | ||
bar: "bar", | ||
eventSignature: "toolingUsage", | ||
}; | ||
const output = await handler(data); | ||
await handler(event); | ||
expect(spyOnAddSignature).toBeCalledWith({ | ||
bar: "bar", | ||
foo: "foo", | ||
eventSignature: "toolingUsage", | ||
}); | ||
}); | ||
it("calls collectMetrics passing a signed event, given that the event is known", async () => { | ||
const event = { | ||
foo: "foo", | ||
bar: "bar", | ||
eventSignature: "toolingUsage", | ||
}; | ||
|
||
await handler(event); | ||
|
||
expect(output).toMatchObject({ | ||
expect(spyOnCollectMetrics).toBeCalledWith({ | ||
created_at: expect.any(Number), | ||
output: data, | ||
dataEventSignature: "packages", | ||
dataEventSignature: "deven-tooling-usage", | ||
owner: "", | ||
repo: "", | ||
output: {}, | ||
payload: { | ||
foo: "foo", | ||
bar: "bar", | ||
eventSignature: "toolingUsage", | ||
}, | ||
}); | ||
}); | ||
|
||
it("...", async () => { | ||
const output = await handler(mergedCompletedSuccessfully); | ||
it("doesn't call collectMetrics if the event is unknown", async () => { | ||
const event = { | ||
foo: "foo", | ||
bar: "bar", | ||
eventSignature: "foo", | ||
}; | ||
|
||
await handler(event); | ||
|
||
expect(spyOnCollectMetrics).not.toBeCalled(); | ||
expect(logger.warning).toBeCalledWith( | ||
LogWarnings.signingEventSignatureNotRecognized | ||
); | ||
}); | ||
|
||
it("calls storeData passing an enhanced data event, given that the metrics can be collects", async () => { | ||
const event = { | ||
foo: "foo", | ||
bar: "bar", | ||
eventSignature: "toolingUsage", | ||
}; | ||
|
||
await handler(event); | ||
|
||
expect(output).toMatchObject({ | ||
expect(spyOnStoreData).toBeCalledWith({ | ||
created_at: expect.any(Number), | ||
dataEventSignature: "merged-pr", | ||
dataEventSignature: "deven-tooling-usage", | ||
output: {}, | ||
owner: "", | ||
payload: { | ||
bar: "bar", | ||
eventSignature: "toolingUsage", | ||
foo: "foo", | ||
}, | ||
repo: "", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
import { allPass, propEq } from "ramda"; | ||
import { DataEventSignature } from "../../interfaces"; | ||
|
||
export const isPullRequestClosed = () => | ||
allPass([ | ||
propEq("eventSignature", "pull_request"), | ||
propEq("action", "closed"), | ||
]); | ||
export const isPullRequestClosed = allPass([ | ||
propEq("eventSignature", "pull_request"), | ||
propEq("action", "closed"), | ||
]); | ||
|
||
export default [[isPullRequestClosed, DataEventSignature.PullRequestClosed]]; |
Oops, something went wrong.