Unverified Commit 6f206f0f authored by Bradley Hilton's avatar Bradley Hilton
Browse files

Add several more tests to the testing app

parent 6b041e0a
# Testing App
What is this for?! Just to test out various pieces of the Rocket.Chat Apps framework via an App.
## Messages
* Prevent: yes, if it has the prefix and ` Prevent this`.
* Extend: yes, if it starts with the prefix. Adds an attachment.
* Modify: yes, if it starts with the prefix. Duplicates the message text.
* Post: yes, if it starts with the prefix. Sends a notification.
// tslint:disable-next-line:max-line-length
import { IConfigurationExtend, IConfigurationModify, IEnvironmentRead, IHttp, ILogger, IMessageBuilder, IMessageExtender, IPersistence, IRead } from '@rocket.chat/apps-ts-definition/accessors';
import { IConfigurationExtend, IConfigurationModify, IEnvironmentRead, IHttp, ILogger, IMessageBuilder, IMessageExtender, IPersistence, IRead, IRoomBuilder, IRoomExtender } from '@rocket.chat/apps-ts-definition/accessors';
import { App } from '@rocket.chat/apps-ts-definition/App';
import { IMessage, IMessageAttachment, IPostMessageSent, IPreMessageSentExtend, IPreMessageSentModify, IPreMessageSentPrevent } from '@rocket.chat/apps-ts-definition/messages';
import { IAppInfo } from '@rocket.chat/apps-ts-definition/metadata';
import { IPostRoomCreate, IPreRoomCreateExtend, IPreRoomCreateModify, IPreRoomCreatePrevent, IRoom, RoomType } from '@rocket.chat/apps-ts-definition/rooms';
import { SettingType } from '@rocket.chat/apps-ts-definition/settings';
import { TestingNoPermission } from './commands/TestingNoPermission';
import { TestingWithPermission } from './commands/TestingWithPermission';
import { TestingSettingsEnum } from './TestingSettingsEnum';
export class TestingApp extends App implements IPreMessageSentPrevent, IPreMessageSentExtend, IPreMessageSentModify, IPostMessageSent {
export class TestingApp extends App implements IPreMessageSentPrevent, IPreMessageSentExtend, IPreMessageSentModify, IPostMessageSent, IPreRoomCreatePrevent, IPreRoomCreateExtend, IPreRoomCreateModify, IPostRoomCreate {
private testingPrefix: string;
constructor(info: IAppInfo, logger: ILogger) {
super(info, logger);
this.testingPrefix = '@testing:';
this.testingPrefix = 'testing-apps';
this.getLogger().debug('TestingApp\'s constructor is called and I logged debug.');
}
public onEnable(environment: IEnvironmentRead, configurationModify: IConfigurationModify): boolean {
this.testingPrefix = environment.getSettings().getValueById('testing-prefix') as string;
this.testingPrefix = environment.getSettings().getValueById(TestingSettingsEnum.TESTING_PREFIX) as string;
return this.testingPrefix.length > 0;
}
......@@ -58,7 +59,7 @@ export class TestingApp extends App implements IPreMessageSentPrevent, IPreMessa
public executePreMessageSentModify(message: IMessage, builder: IMessageBuilder, read: IRead, http: IHttp, persistence: IPersistence): IMessage {
const text = message.text;
return builder.setText(text + '\n\n >' + text).getMessage();
return builder.setText(text + '\n\n> ' + text).getMessage();
}
// Test out IPostMessageSent
......@@ -71,19 +72,147 @@ export class TestingApp extends App implements IPreMessageSentPrevent, IPreMessa
read.getNotifier().notifyUser(message.sender, message);
}
// Test out Commands
// Test out IPreRoomCreatePrevent
public checkPreRoomCreatePrevent(room: IRoom): boolean {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreRoomCreatePrevent
public executePreRoomCreatePrevent(room: IRoom, read: IRead, http: IHttp, persistence: IPersistence): boolean {
return room.slugifiedName === `${ this.testingPrefix }-prevent`;
}
// Test out IPreRoomCreateExtend
public checkPreRoomCreateExtend(room: IRoom): boolean {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreRoomCreateExtend
public executePreRoomCreateExtend(room: IRoom, extend: IRoomExtender, read: IRead, http: IHttp, persistence: IPersistence): IRoom {
const bot = read.getUserReader().getById('rocket.cat');
return extend.addMember(bot).getRoom();
}
// Test out IPreRoomCreateModify
public checkPreRoomCreateModify(room: IRoom): boolean {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreRoomCreateModify
public executePreRoomCreateModify(room: IRoom, builder: IRoomBuilder, read: IRead, http: IHttp, persistence: IPersistence): IRoom {
room.displaySystemMessages = false;
return room;
}
// Test out IPostRoomCreate
public checkPostRoomCreate(room: IRoom): boolean {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPostRoomCreate
public executePostRoomCreate(room: IRoom, read: IRead, http: IHttp, persistence: IPersistence): void {
const msg = read.getNotifier().getMessageBuilder()
.setRoom(room).setText(`Welcome to #${ room.slugifiedName }! _testing:_ :heavy_check_mark:`)
.setEmojiAvatar(':ghost:').getMessage();
read.getNotifier().notifyRoom(room, msg);
}
// Test out various configuration extentions
protected extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead) {
configuration.slashCommands.provideSlashCommand(new TestingNoPermission());
configuration.slashCommands.provideSlashCommand(new TestingWithPermission());
configuration.settings.provideSetting({
id: 'testing-prefix',
id: TestingSettingsEnum.TESTING_PREFIX,
type: SettingType.STRING,
packageValue: '@testing:',
packageValue: 'testing-apps',
required: true,
public: false,
i18nLabel: 'TestingApp_TestingPrefix',
i18nDescription: 'TestingApp_TestingPrefix_Description',
});
configuration.settings.provideSetting({
id: TestingSettingsEnum.TESTING_A_BOOLEAN,
type: SettingType.BOOLEAN,
packageValue: true,
required: false,
public: false,
i18nLabel: 'TestingApp_TestingBoolean',
i18nDescription: 'TestingApp_TestingBoolean_Description',
});
configuration.settings.provideSetting({
id: TestingSettingsEnum.TESTING_A_COLOR,
type: SettingType.COLOR,
packageValue: '#00ff33',
required: false,
public: false,
i18nLabel: 'TestingApp_TestingColor',
i18nDescription: 'TestingApp_TestingColor_Description',
});
configuration.settings.provideSetting({
id: TestingSettingsEnum.TESTING_A_NUMBER,
type: SettingType.NUMBER,
packageValue: 1337,
required: false,
public: false,
i18nLabel: 'TestingApp_TestingNumber',
i18nDescription: 'TestingApp_TestingNumber_Description',
});
configuration.settings.provideSetting({
id: TestingSettingsEnum.TESTING_A_SELECT,
type: SettingType.SELECT,
packageValue: 'second',
required: false,
public: false,
i18nLabel: 'TestingApp_TestingSelect',
i18nDescription: 'TestingApp_TestingSelect_Description',
values: [
{
key: 'first',
i18nLabel: 'TestingApp_FirstSelectOption',
},
{
key: 'second',
i18nLabel: 'TestingApp_SecondSelectOption',
},
{
key: 'third',
i18nLabel: 'TestingApp_ThirdSelectOption',
},
{
key: 'last',
i18nLabel: 'TestingApp_LastSelectOption',
},
],
});
configuration.settings.provideSetting({
id: TestingSettingsEnum.TESTING_A_MULTI_LINE_STRING,
type: SettingType.STRING,
multiline: true,
// tslint:disable-next-line:max-line-length
packageValue: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nNunc faucibus lacus erat, quis dapibus leo tempor eu. Maecenas vel tellus non ligula consectetur aliquet. Nam tempor iaculis lectus, in tincidunt lacus vehicula in. Nam eu tortor dapibus tellus condimentum faucibus a ac enim. Morbi euismod suscipit pellentesque. Etiam faucibus erat vitae neque fringilla, non elementum massa tincidunt. Cras pharetra, lorem eu facilisis dapibus, nibh magna scelerisque est, eu vulputate augue sapien sed metus. Duis volutpat tempus placerat. Donec in urna pulvinar, eleifend lacus at, porttitor velit. Morbi finibus molestie massa, quis aliquet ex euismod pellentesque. Proin semper imperdiet sapien sed ornare. Morbi fermentum metus sodales malesuada cursus. In nec massa eros.',
required: false,
public: false,
i18nLabel: 'TestingApp_TestingMultiString',
i18nDescription: 'TestingApp_TestingMultiString_Description',
});
configuration.settings.provideSetting({
id: TestingSettingsEnum.TESTING_A_CODE,
type: SettingType.CODE,
packageValue: 'export class TestingSetting implements ISetting {\n public id: \'something-cool\'\n}',
required: false,
public: false,
i18nLabel: 'TestingApp_TestingCode',
i18nDescription: 'TestingApp_TestingCode_Description',
});
}
}
export enum TestingSettingsEnum {
TESTING_PREFIX = 'testing-prefix',
TESTING_A_BOOLEAN = 'testing-boolean',
TESTING_A_COLOR = 'testing-color',
TESTING_A_NUMBER = 'testing-number',
TESTING_A_SELECT = 'testing-select',
TESTING_A_MULTI_LINE_STRING = 'testing-multi-string',
TESTING_A_CODE = 'testing-code',
}
......@@ -3,7 +3,7 @@
"name": "Testing App",
"nameSlug": "testing-app",
"description": "A Rocket.Chat Application used to test out the various features.",
"version": "0.0.1",
"version": "0.0.3",
"requiredApiVersion": ">=0.7.15",
"author": {
"name": "Bradley Hilton",
......
......@@ -15,6 +15,7 @@ export class TestingNoPermission implements ISlashCommand {
// tslint:disable-next-line:max-line-length
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): void {
const msg = modify.getNotifer().getMessageBuilder()
.setRoom(context.getRoom())
.setUsernameAlias('Testing').setEmojiAvatar(':ghost:')
.setText('You have successfully tested the command, good job.').getMessage();
......
......@@ -17,6 +17,7 @@ export class TestingWithPermission implements ISlashCommand {
// tslint:disable-next-line:max-line-length
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): void {
const msg = modify.getNotifer().getMessageBuilder()
.setRoom(context.getRoom())
.setUsernameAlias('Testing').setEmojiAvatar(':ghost:')
.setText('You have permission, congrats.').getMessage();
......
......@@ -3,5 +3,21 @@
"TestingApp_CmdWithPerm": "Command restricted by a permission.",
"TestingApp_CmdNoPerm": "Command is restrictionless.",
"TestingApp_TestingPrefix": "Prefix for Tests",
"TestingApp_TestingPrefix_Description": "Several tests require a prefix, on messages, in order to touch them. What prefix should that be?"
"TestingApp_TestingPrefix_Description": "Several tests require a prefix, on messages, in order to touch them. What prefix should that be?",
"TestingApp_TestingBoolean": "Boolean Testing",
"TestingApp_TestingBoolean_Description": "Just a setting that tests the `boolean` setting type. It's mostly ignored except during testing. ;)",
"TestingApp_TestingColor": "Color Testing",
"TestingApp_TestingColor_Description": "Another setting but this one tests the `color` setting type. :D",
"TestingApp_TestingNumber": "Number Testing",
"TestingApp_TestingNumber_Description": "Which even another setting. However, this one tests the `number` setting type. :)",
"TestingApp_TestingSelect": "Select Testing",
"TestingApp_TestingSelect_Description": "Here is a setting. A setting which tests the `select` setting type. :p",
"TestingApp_FirstSelectOption": "First Option",
"TestingApp_SecondSelectOption": "Second Option",
"TestingApp_ThirdSelectOption": "Third Option",
"TestingApp_LastSelectOption": "Last Option",
"TestingApp_TestingMultiString": "Multi Line String Test",
"TestingApp_TestingMultiString_Description": "Why am I writing descriptions? These are tests for crying out loud, like this one tests a setting which is multuple lines of the `string` setting type. (..)",
"TestingApp_TestingCode": "Code Test",
"TestingApp_TestingCode_Description": "I'm bored. Please test the `code` setting type. :x"
}
......@@ -32,7 +32,7 @@
"resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-0.4.8.tgz",
"integrity": "sha512-QZ+VNeMf4RDWKTd8O6t8/enwOSNVla6hcpvZYAb9nd8D2Syi6RstcLCYCFjaM+Vc6EX5Dscv4nUjXJtsY/2KOw==",
"requires": {
"@rocket.chat/apps-ts-definition": "0.7.15",
"@rocket.chat/apps-ts-definition": "0.7.16",
"adm-zip": "0.4.7",
"semver": "5.5.0",
"stack-trace": "0.0.10",
......@@ -48,9 +48,9 @@
}
},
"@rocket.chat/apps-ts-definition": {
"version": "0.7.15",
"resolved": "https://registry.npmjs.org/@rocket.chat/apps-ts-definition/-/apps-ts-definition-0.7.15.tgz",
"integrity": "sha512-mOD1C/bTfeOY77/Rnlq8nLuCQSUTq8qeHH604DiehJJGD3gToEt2yIAbKOdFrkoOCV2T5z6eXzyBifMjsreAbQ=="
"version": "0.7.16",
"resolved": "https://registry.npmjs.org/@rocket.chat/apps-ts-definition/-/apps-ts-definition-0.7.16.tgz",
"integrity": "sha512-bCguBIH0rXn/58bY/+y/JGAALo/AjWikI9vhPu6IH9pBbIM2w57FAQT8Rd38B0Z+UK+uBsqlHdz5EWJPcU7ESA=="
},
"@types/body-parser": {
"version": "1.16.4",
......@@ -637,10 +637,19 @@
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=",
"dev": true
},
"colors": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz",
"integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=",
"color-convert": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz",
"integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true
},
"combined-stream": {
......@@ -653,9 +662,9 @@
}
},
"commander": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
"version": "2.15.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
"integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==",
"dev": true
},
"component-bind": {
......@@ -901,9 +910,9 @@
"dev": true
},
"diff": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz",
"integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=",
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
"dev": true
},
"doctrine": {
......@@ -2792,6 +2801,12 @@
"integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=",
"dev": true
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"has-gulplog": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/has-gulplog/-/has-gulplog-0.1.0.tgz",
......@@ -5400,44 +5415,75 @@
"dev": true
},
"tslib": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.7.1.tgz",
"integrity": "sha1-vIAEFkaRkjp5/oN4u+s9ogF1OOw=",
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.0.tgz",
"integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==",
"dev": true
},
"tslint": {
"version": "5.4.3",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.4.3.tgz",
"integrity": "sha1-dhyEArgONHt3M6BDkKdXslNYBGc=",
"version": "5.9.1",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.9.1.tgz",
"integrity": "sha1-ElX4ej/1frCw4fDmEKi0dIBGya4=",
"dev": true,
"requires": {
"babel-code-frame": "6.22.0",
"colors": "1.1.2",
"commander": "2.11.0",
"diff": "3.2.0",
"builtin-modules": "1.1.1",
"chalk": "2.3.2",
"commander": "2.15.1",
"diff": "3.5.0",
"glob": "7.1.2",
"js-yaml": "3.8.4",
"minimatch": "3.0.4",
"resolve": "1.3.3",
"semver": "5.3.0",
"tslib": "1.7.1",
"tsutils": "2.5.1"
"semver": "5.5.0",
"tslib": "1.9.0",
"tsutils": "2.26.0"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "1.9.1"
}
},
"chalk": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz",
"integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==",
"dev": true,
"requires": {
"ansi-styles": "3.2.1",
"escape-string-regexp": "1.0.5",
"supports-color": "5.3.0"
}
},
"semver": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=",
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==",
"dev": true
},
"supports-color": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz",
"integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==",
"dev": true,
"requires": {
"has-flag": "3.0.0"
}
}
}
},
"tsutils": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.5.1.tgz",
"integrity": "sha1-wgATkMee7Bpcz6esEtWZY5aD4M8=",
"version": "2.26.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.26.0.tgz",
"integrity": "sha512-hXUttgxeaZ/uPP/dpeiWUHbP5h744mPrfN2YFFtcZzd7vBRPBP6Knr0Mt6Bd+5SntMn8/1r6IGFeYPDSBIIPpg==",
"dev": true,
"requires": {
"tslib": "1.7.1"
"tslib": "1.9.0"
}
},
"tunnel-agent": {
......
......@@ -6,7 +6,15 @@
"no-duplicate-variable": true,
"object-literal-sort-keys": false,
"quotemark": [true, "single"],
"max-line-length": 120
"max-line-length": [true, {
"limit": 160,
"ignore-pattern": "^import | *export .*? {"
}]
},
"linterOptions": {
"exclude": [
"apps/**/node_modules"
]
},
"jsRules": {
"quotemark": [true, "single"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment