Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
V3 (#7)
Browse files Browse the repository at this point in the history
* Drop node 6&7

* Add badge

* Update .npmpackagejsonlintrc.json

* Update package.json

* LInting tuneup

* Update HipChatRoomNotification.js

* Update networkRequest.test.js

* Update networkRequest.test.js

* Update networkRequest.test.js
  • Loading branch information
tclindner authored Apr 28, 2019
1 parent cbf6a72 commit 4fee1e2
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 350 deletions.
3 changes: 2 additions & 1 deletion .npmpackagejsonlintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "npm-package-json-lint-config-tc",
"rules": {
"require-peerDependencies": "off"
"require-peerDependencies": "off",
"valid-values-engines": "off"
}
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Removed


## [3.0.0] - 2019-04-28
### Changed
- Bump dependencies

### Removed
- Dropped support for Node 6 and 7.

## [2.0.0] - 2018-06-02
### Changed
- Bump dependencies
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

### Node

* [Node.js](https://nodejs.org/) - v6.0.0+
* [npm](https://www.npmjs.com/) - v3.0.0+
* [Node.js](https://nodejs.org/) - v8.0.0+
* [npm](https://www.npmjs.com/) - v5.0.0+

## Install project dependencies

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![license](https://img.shields.io/github/license/tclindner/hipchat-room-notification-api.svg?maxAge=2592000&style=flat-square)](https://github.com/tclindner/hipchat-room-notification-api/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/v/hipchat-room-notification-api.svg?maxAge=2592000?style=flat-square)](https://www.npmjs.com/package/hipchat-room-notification-api)
[![Travis](https://img.shields.io/travis/tclindner/hipchat-room-notification-api.svg?maxAge=2592000?style=flat-square)](https://travis-ci.org/tclindner/hipchat-room-notification-api)
[![CircleCI](https://circleci.com/gh/tclindner/hipchat-room-notification-api.svg?style=svg&circle-token=84359b572224713bf3ad7aeff27bece303339ad6)](https://circleci.com/gh/tclindner/hipchat-room-notification-api)
[![Dependency Status](https://david-dm.org/tclindner/hipchat-room-notification-api.svg?style=flat-square)](https://david-dm.org/tclindner/hipchat-room-notification-api)
[![devDependency Status](https://david-dm.org/tclindner/hipchat-room-notification-api/dev-status.svg?style=flat-square)](https://david-dm.org/tclindner/hipchat-room-notification-api#info=devDependencies)

Expand All @@ -20,8 +20,8 @@ First thing first, let's make sure you have the necessary pre-requisites.

#### Node

* [Node.js](https://nodejs.org/) - v6.0.0+
* [npm](http://npmjs.com) - v3.0.0+
* [Node.js](https://nodejs.org/) - v8.0.0+
* [npm](http://npmjs.com) - v5.0.0+

### Package

Expand Down
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hipchat-room-notification-api",
"version": "2.0.0",
"version": "3.0.0",
"description": "Node.js wrapper for HipChat's v2 Send Room Notification API",
"keywords": [
"hipchat",
Expand Down Expand Up @@ -28,27 +28,25 @@
"eslint": "eslint . --format=node_modules/eslint-formatter-pretty",
"lint": "npm run npmpackagejsonlint && npm run eslint",
"npmpackagejsonlint": "npmPkgJsonLint .",
"test": "mocha test --recursive",
"coverage": "nyc --extension .js --check-coverage --lines 97 --branches 90 --functions 95 npm test"
"test": "jest"
},
"dependencies": {
"request": "^2.87.0"
"request": "^2.88.0"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^4.19.1",
"eslint-config-tc": "^3.0.0",
"eslint-formatter-pretty": "^1.3.0",
"npm-package-json-lint": "^3.4.1",
"eslint": "^5.16.0",
"eslint-config-tc": "^6.4.0",
"eslint-formatter-pretty": "^2.1.1",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-prettier": "^3.0.1",
"jest": "^24.7.1",
"npm-package-json-lint": "^3.6.0",
"npm-package-json-lint-config-tc": "^2.1.0",
"mocha": "^5.2.0",
"nyc": "^11.7.1",
"sinon": "^4.5.0"
"prettier": "^1.17.0"
},
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
"node": ">=8.0.0",
"npm": ">=5.0.0"
},
"license": "MIT"
}
55 changes: 26 additions & 29 deletions src/HipChatRoomNotification.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';

const request = require('request');
const Validator = require('./Validator');

const SUCCESSFUL_POST = 204;

/* eslint no-undefined: 'off', object-curly-newline: 'off', id-length: 'off', class-methods: 'off', camelcase: 'off', max-params: 'off', no-unused-vars: 'off' */

class HipChatRoomNotification {

/**
* Creates an instance of HipChatRoomNotification.
*
Expand Down Expand Up @@ -108,9 +106,9 @@ class HipChatRoomNotification {
*/
addCard(id, style, title) {
this.requestJson.card = {
id: id,
style: style,
title: title
id,
style,
title
};
this.isCard = true;
}
Expand All @@ -125,7 +123,7 @@ class HipChatRoomNotification {
*/
addCardThumbnail(url) {
this.requestJson.card.thumbnail = {
url: url
url
};
}

Expand All @@ -142,10 +140,10 @@ class HipChatRoomNotification {
*/
addCardThumbnailDetails(url, url2x, width, height) {
this.requestJson.card.thumbnail = {
url: url,
url2x: url2x,
width: width,
height: height
url,
url2x,
width,
height
};
}

Expand All @@ -159,7 +157,7 @@ class HipChatRoomNotification {
*/
addActivity(html) {
this.requestJson.card.activity = {
html: html
html
};
}

Expand All @@ -174,7 +172,7 @@ class HipChatRoomNotification {
*/
addActivityWithIcon(html, iconUrl) {
this.requestJson.card.activity = {
html: html,
html,
icon: {
url: iconUrl
}
Expand All @@ -193,9 +191,9 @@ class HipChatRoomNotification {
*/
addActivityWithIconDetails(html, iconUrl, icon2xUrl) {
this.requestJson.card.activity = {
html: html,
html,
icon: {
'url': iconUrl,
url: iconUrl,
'url@2x': icon2xUrl
}
};
Expand Down Expand Up @@ -247,7 +245,7 @@ class HipChatRoomNotification {
addCardDescription(description, format) {
this.requestJson.card.description = {
value: description,
format: format
format
};
}

Expand All @@ -264,10 +262,10 @@ class HipChatRoomNotification {
*/
addCardAttribute(label, description, style) {
const attribute = {
label: label,
label,
value: {
label: description,
style: style
style
}
};

Expand All @@ -288,11 +286,11 @@ class HipChatRoomNotification {
*/
addCardAttributeWithUrl(label, description, style, url) {
const attribute = {
label: label,
label,
value: {
label: description,
style: style,
url: url
style,
url
}
};

Expand All @@ -313,10 +311,10 @@ class HipChatRoomNotification {
*/
addCardAttributeWithIcon(label, description, style, iconUrl) {
const attribute = {
label: label,
label,
value: {
label: description,
style: style,
style,
icon: iconUrl
}
};
Expand All @@ -339,12 +337,12 @@ class HipChatRoomNotification {
*/
addCardAttributeWithIconAndUrl(label, description, style, iconUrl, url) {
const attribute = {
label: label,
label,
value: {
label: description,
style: style,
style,
icon: iconUrl,
url: url
url
}
};

Expand Down Expand Up @@ -392,7 +390,7 @@ class HipChatRoomNotification {
*/
addCardIconDetails(iconUrl, icon2xUrl) {
this.requestJson.card.icon = {
'url': iconUrl,
url: iconUrl,
'url@2x': icon2xUrl
};
}
Expand Down Expand Up @@ -446,7 +444,7 @@ class HipChatRoomNotification {
method: 'POST',
json: this.requestJson,
headers: {
'Authorization': this.authToken,
Authorization: this.authToken,
'Content-Type': 'application/json'
}
};
Expand All @@ -465,7 +463,6 @@ class HipChatRoomNotification {
}
});
}

}

module.exports = HipChatRoomNotification;
22 changes: 2 additions & 20 deletions src/Validator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

const noErrors = 0;
const notFound = -1;

class Validator {

/**
* Creates an instance of Validator.
* @param {String} requestObject HipChat API object
Expand Down Expand Up @@ -128,14 +125,7 @@ class Validator {
* @returns {Undefined} No return
*/
_validateColor() {
const validValues = [
'yellow',
'green',
'red',
'purple',
'gray',
'random'
];
const validValues = ['yellow', 'green', 'red', 'purple', 'gray', 'random'];

if (this.requestObject.hasOwnProperty('color')) {
if (validValues.indexOf(this.requestObject.color) === notFound) {
Expand Down Expand Up @@ -203,13 +193,7 @@ class Validator {
* @returns {Undefined} No return
*/
_validateStyle() {
const validValues = [
'file',
'image',
'application',
'link',
'media'
];
const validValues = ['file', 'image', 'application', 'link', 'media'];

if (this.requestObject.hasOwnProperty('card')) {
if (this.requestObject.card.hasOwnProperty('style')) {
Expand Down Expand Up @@ -310,8 +294,6 @@ class Validator {
}
}
}


}

module.exports = Validator;
19 changes: 7 additions & 12 deletions test/basicMessage.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
'use strict';

const chai = require('chai');
const HipChatRoomNotification = require('./../src/HipChatRoomNotification');

const should = chai.should();

/* eslint camelcase: 'off' */

describe('HipChatRoomNotification Unit Tests', function() {
describe('Basic message', function() {
describe('HipChatRoomNotification Unit Tests', () => {
describe('Basic message', () => {
let hipChatRoomNotification;

beforeEach(function() {
beforeEach(() => {
hipChatRoomNotification = new HipChatRoomNotification('https://www.example.com', '1', 'abcd1234');
});

it('validate initialization', function() {
test('validate initialization', () => {
const expected = {
message_format: 'html',
color: 'yellow',
notify: false
};

hipChatRoomNotification._getRequestJson().should.deep.equal(expected);
expect(hipChatRoomNotification._getRequestJson()).toStrictEqual(expected);
});

it('custom basic message', function() {
test('custom basic message', () => {
const expected = {
from: 'from',
message_format: 'text',
Expand All @@ -39,7 +34,7 @@ describe('HipChatRoomNotification Unit Tests', function() {
hipChatRoomNotification.setColor('green');
hipChatRoomNotification.shouldNotify();
hipChatRoomNotification.setMessage('message');
hipChatRoomNotification._getRequestJson().should.deep.equal(expected);
expect(hipChatRoomNotification._getRequestJson()).toStrictEqual(expected);
});
});
});
Loading

0 comments on commit 4fee1e2

Please sign in to comment.