Skip to content

Commit

Permalink
introduce proper testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Skitionek committed Oct 9, 2024
1 parent 190d4d9 commit 9d22e91
Show file tree
Hide file tree
Showing 5 changed files with 14,434 additions and 14,413 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.env
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Test",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": [
"-i"
],
"internalConsoleOptions": "openOnSessionStart",
"envFile": "${workspaceFolder}/.env"
}
]
}
168 changes: 165 additions & 3 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,165 @@
test('throws invalid number', async() => {
//todo - many tests are checked in 'test.yml' action
});
const core = require('@actions/core');

const action = './src';

const webhook_url = process.env.MSTEAMS_WEBHOOK;
const dry_run = process.env.DRY_RUN.toLowerCase() == "true";

const setInputsMock = (inputs) =>
jest.fn().mockImplementation((name, options) => inputs[name]);

afterEach(() => {
jest.resetModules();
});

test('One with everything', () => {
core.getInput = setInputsMock({
webhook_url,
needs: JSON.stringify({

}),
job: JSON.stringify({

}),
steps: JSON.stringify({

}),
dry_run
});
require(action);
});

test('One with needs', () => {
core.getInput = setInputsMock({
webhook_url,
needs: JSON.stringify({

}),
job: JSON.stringify({

}),
steps: JSON.stringify({

}),
dry_run
});
require('./src');
});

test('One with steps', () => {
core.getInput = setInputsMock({
webhook_url,
needs: JSON.stringify({

}),
job: JSON.stringify({

}),
steps: JSON.stringify({

}),
dry_run
});
require(action);
});

test('One failure', () => {
core.getInput = setInputsMock({
webhook_url,
needs: JSON.stringify({

}),
job: JSON.stringify({

}),
steps: JSON.stringify({

}),
dry_run
});
require(action);
});

test('One with little info', () => {
core.getInput = setInputsMock({
webhook_url,
dry_run
});
require(action);
});

test('One without emails', () => {
core.getInput = setInputsMock({
webhook_url,
title: "`Overwrote title in ${workflow_link}`",
job: JSON.stringify({

}),
steps: JSON.stringify({

}),
dry_run
});
require(action);
});

test('One with emails', () => {
core.getInput = setInputsMock({
webhook_url,
title: "`Overwrote title in ${workflow_link}`",
msteams_emails: "mm@mm.mm, yy@yy.yy, rr@rr.rr",
job: JSON.stringify({

}),
steps: JSON.stringify({

}),
dry_run
});
require(action);
});

test('One with overwrite', () => {
core.getInput = setInputsMock({
webhook_url,
title: "`Overwrote title in ${workflow_link}`",
job: JSON.stringify({

}),
steps: JSON.stringify({

}),
dry_run
});
require(action);
});

test('One with raw data', () => {
core.getInput = setInputsMock({
webhook_url,
raw: JSON.stringify({
"type": "message",
"attachments":
[
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content":
{
"type": "AdaptiveCard",
"body":
[
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Test title text"
}
]
}
}
]
}),
dry_run
});
require(action);
});
Loading

0 comments on commit 9d22e91

Please sign in to comment.