2018-09-15 20:23:05 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
|
|
|
import { Qenv } from '@pushrocks/qenv';
|
2017-09-17 12:53:00 +00:00
|
|
|
|
2018-09-15 20:23:05 +00:00
|
|
|
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
|
2017-09-17 12:53:00 +00:00
|
|
|
|
2018-09-15 20:23:05 +00:00
|
|
|
import * as slackme from '../ts/index';
|
2017-09-14 05:20:26 +00:00
|
|
|
|
2019-09-18 14:47:31 +00:00
|
|
|
let testSlackAccount: slackme.SlackAccount;
|
2018-09-15 20:23:05 +00:00
|
|
|
let testSlackMessage: slackme.SlackMessage;
|
2017-09-17 12:53:00 +00:00
|
|
|
|
2019-09-18 10:26:31 +00:00
|
|
|
tap.test('should create a valid slackme instance', async (tools) => {
|
2019-09-18 14:47:31 +00:00
|
|
|
testSlackAccount = new slackme.SlackAccount(testQenv.getEnvVarOnDemand('SLACK_TOKEN'));
|
2018-09-15 20:23:05 +00:00
|
|
|
});
|
2017-09-17 12:53:00 +00:00
|
|
|
|
2019-09-18 10:26:31 +00:00
|
|
|
tap.test('should send a message to Slack', async (tools) => {
|
2019-09-18 14:47:31 +00:00
|
|
|
const messageOptions = {
|
2019-09-05 11:08:42 +00:00
|
|
|
author_name: 'GitLab CI',
|
|
|
|
author_link: 'https://gitlab.com/',
|
|
|
|
pretext: '*Good News*: Build successfull!',
|
|
|
|
color: '#3cb371',
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
title: 'Branch',
|
|
|
|
value: 'Lossless Cloud',
|
|
|
|
short: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Product ID',
|
|
|
|
value: 'pushrocks',
|
|
|
|
short: true
|
|
|
|
}
|
2019-09-18 10:26:31 +00:00
|
|
|
]
|
2019-09-18 14:47:31 +00:00
|
|
|
};
|
|
|
|
await testSlackAccount.sendMessage({
|
2019-09-18 13:47:51 +00:00
|
|
|
channelArg: 'random',
|
2019-09-18 14:47:31 +00:00
|
|
|
messageOptions: messageOptions,
|
2019-09-18 13:47:51 +00:00
|
|
|
mode: 'new'
|
|
|
|
});
|
2019-09-05 11:08:42 +00:00
|
|
|
});
|
|
|
|
|
2019-09-18 10:26:31 +00:00
|
|
|
tap.test('should send a message to Slack by directly calling the message', async (tools) => {
|
2019-09-05 11:09:13 +00:00
|
|
|
testSlackMessage = new slackme.SlackMessage(
|
2019-09-18 14:47:31 +00:00
|
|
|
testSlackAccount,
|
2019-09-05 11:09:13 +00:00
|
|
|
{
|
|
|
|
author_name: 'GitLab CI',
|
|
|
|
author_link: 'https://gitlab.com/',
|
|
|
|
pretext: '*Good News*: Build successfull!',
|
|
|
|
color: '#3cb371',
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
title: 'Branch',
|
|
|
|
value: 'Lossless Cloud',
|
|
|
|
short: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Product ID',
|
|
|
|
value: 'pushrocks',
|
|
|
|
short: true
|
|
|
|
}
|
2019-09-18 10:26:31 +00:00
|
|
|
]
|
2019-09-18 14:47:31 +00:00
|
|
|
}
|
2019-09-05 11:09:13 +00:00
|
|
|
);
|
2019-09-05 11:08:42 +00:00
|
|
|
await testSlackMessage.sendToRoom('random');
|
2019-09-18 10:28:41 +00:00
|
|
|
await tools.delayFor(1000);
|
2019-09-18 10:26:31 +00:00
|
|
|
await testSlackMessage.updateAndSend({
|
|
|
|
author_name: 'GitLab CI',
|
|
|
|
author_link: 'https://gitlab.com/',
|
|
|
|
pretext: '*Good News*: Build successfull!',
|
|
|
|
color: '#3cb371',
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
title: 'Branch',
|
|
|
|
value: 'Lossless Studio',
|
|
|
|
short: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Product ID',
|
|
|
|
value: 'pushrocks',
|
|
|
|
short: true
|
|
|
|
}
|
|
|
|
]
|
2019-09-18 13:47:51 +00:00
|
|
|
});
|
|
|
|
await testSlackMessage.updateAndSend({
|
|
|
|
author_name: 'GitLab CI',
|
|
|
|
author_link: 'https://gitlab.com/',
|
|
|
|
pretext: '*Good News*: Build successfull!',
|
|
|
|
color: '#3cb371',
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
title: 'Branch',
|
|
|
|
value: 'Lossless Studio',
|
|
|
|
short: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Product ID',
|
|
|
|
value: 'onboard.me',
|
|
|
|
short: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
await testSlackMessage.startThread({
|
|
|
|
author_name: 'Lossless Compliance',
|
|
|
|
author_link: 'https://gitlab.com/',
|
|
|
|
pretext: '*Good News*: Build successfull!',
|
|
|
|
color: '#3cb371',
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
title: 'Branch',
|
|
|
|
value: 'Lossless Studio',
|
|
|
|
short: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Product ID',
|
|
|
|
value: 'pushrocks',
|
|
|
|
short: true
|
|
|
|
}
|
|
|
|
]
|
2019-09-18 10:26:31 +00:00
|
|
|
})
|
2018-09-15 20:23:05 +00:00
|
|
|
});
|
2018-01-10 20:45:25 +00:00
|
|
|
|
2019-09-18 14:47:31 +00:00
|
|
|
tap.test('should send logs', async () => {
|
|
|
|
const slackLog = new slackme.SlackLog({
|
|
|
|
slackAccount: testSlackAccount,
|
|
|
|
channelName: 'random'
|
|
|
|
})
|
|
|
|
for (let i = 0; i < 30; i++) {
|
|
|
|
await slackLog.sendLogLine('hi there');
|
|
|
|
await slackLog.sendLogLine('so awesome');
|
|
|
|
await slackLog.sendLogLine('really');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2018-09-15 20:23:05 +00:00
|
|
|
tap.start();
|