generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#9 add more tests, refactor
- Loading branch information
Showing
13 changed files
with
157 additions
and
48 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
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.
Large diffs are not rendered by default.
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
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
63 changes: 63 additions & 0 deletions
63
src/payload/customize-card/CustomizeCard.test/CustomizeCard.test.js
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const CustomizeCard = require('../CustomizeCard'); | ||
const expectedPayLoad = require('./expectedPayLoadObject'); | ||
|
||
describe('Verify JSON payload', () => { | ||
|
||
test('Only message', () => { | ||
const message = 'Only message'; | ||
|
||
const payload = new CustomizeCard(message, { status: '' }).constructCard(); | ||
|
||
expect(payload).toMatchObject(expectedPayLoad({message, statusText: '', statusColour: 'default',})); | ||
}); | ||
|
||
test('Message with status success', () => { | ||
const message = 'Message with success status'; | ||
const statusText = 'Success'; | ||
const statusColour = 'good'; | ||
const payload = new CustomizeCard(message, {status: statusText,}).constructCard(); | ||
|
||
expect(payload).toMatchObject(expectedPayLoad({message, statusText, statusColour,})); | ||
}); | ||
|
||
test('Message with custom status', () => { | ||
const message = 'Message with custom status'; | ||
const statusText = 'Custom status'; | ||
const statusColour = 'default'; | ||
const payload = new CustomizeCard(message, {status: statusText,}).constructCard(); | ||
|
||
expect(payload).toMatchObject(expectedPayLoad({message, statusText, statusColour,})); | ||
}); | ||
|
||
describe('With env variables', () => { | ||
const GITHUB_SERVER_URL = "GITHUB_SERVER_URL"; | ||
const GITHUB_REPOSITORY = "GITHUB_REPOSITORY"; | ||
const GITHUB_RUN_ID = "GITHUB_RUN_ID"; | ||
const GITHUB_SHA = "GITHUB_SHA"; | ||
const SHOULD_DISPLAY_VIEW_RUN_BUTTON = "SHOULD_DISPLAY_VIEW_RUN_BUTTON"; | ||
|
||
const githubServerUrl = 'https://foo'; | ||
const githubRepository = 'notify'; | ||
const githubRunId = 1234; | ||
|
||
beforeEach(() => { | ||
delete process.env[GITHUB_SERVER_URL]; | ||
delete process.env[GITHUB_REPOSITORY]; | ||
delete process.env[GITHUB_RUN_ID]; | ||
delete process.env[GITHUB_SHA]; | ||
}); | ||
|
||
test('Payload should not have run URL when view run env variable is set to false', () => { | ||
process.env = Object.assign(process.env, { | ||
[GITHUB_SERVER_URL]: githubServerUrl, [GITHUB_REPOSITORY]: githubRepository, [GITHUB_RUN_ID]: githubRunId, | ||
[SHOULD_DISPLAY_VIEW_RUN_BUTTON]: 'false' | ||
}); | ||
const message = 'Message with cancelled status'; | ||
const statusText = 'Cancelled'; | ||
const statusColour = 'warning'; | ||
const payload = new CustomizeCard(message, {status: statusText,}).constructCard(); | ||
|
||
expect(payload).toMatchObject(expectedPayLoad({message, statusText, statusColour,})); | ||
}); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
src/payload/customize-card/CustomizeCard.test/expectedPayLoadObject.js
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const expectedPayLoadObject = ({ | ||
message, statusText, statusColour | ||
}) => ({ | ||
"type": "message", "attachments": [{ | ||
"contentType": "application/vnd.microsoft.card.adaptive", "contentUrl": null, "content": { | ||
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json", | ||
"type": "AdaptiveCard", | ||
"version": "1.2", | ||
"msteams": {"width": "Full"}, | ||
"body": [{ | ||
"type": "RichTextBlock", "isVisible": statusText !== '', "inlines": [{ | ||
"type": "TextRun", "text": "Status: ", "wrap": true, "fontType": "monospace" | ||
}, { | ||
"type": "TextRun", | ||
"text": statusText, | ||
"wrap": true, | ||
"color": statusColour, | ||
"weight": "bolder", | ||
"fontType": "monospace" | ||
}] | ||
}, { | ||
"type": "ColumnSet", "columns": [{ | ||
"type": "Column", | ||
"width": "stretch", | ||
"style": "emphasis", | ||
"items": [{"type": "TextBlock", "text": message, "wrap": true}] | ||
}, { | ||
"type": "Column", | ||
"width": "auto", | ||
"verticalContentAlignment": "center", | ||
"isVisible": false, | ||
"items": [{"type": "ActionSet", "actions": []}, {"type": "ActionSet", "actions": []}] | ||
}] | ||
}] | ||
} | ||
}] | ||
}); | ||
|
||
module.exports = expectedPayLoadObject; |
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,7 +1,7 @@ | ||
const CustomizeCard = require("./customize-card/CustomizeCard"); | ||
|
||
let payLoad = function constructPayload(message, options) { | ||
return new CustomizeCard(message, options).constructCard(); | ||
let payLoad = function constructPayload(message, { status, }) { | ||
return new CustomizeCard(message, { status, }).constructCard(); | ||
}; | ||
|
||
module.exports = payLoad; |
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