Skip to content

Commit

Permalink
#50 Add user state response (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ro31337 committed Jun 17, 2016
1 parent e9fc4e3 commit 3ef1811
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/responses/user-state-response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Response from './response';
import objectAssign from 'object-assign';

/**
* User state response. Used to update user's state with new values.
* While updating unspecified keys remain untouched. Specified keys are
* updated.
*
* @author Roman Pushkin (roman.pushkin@gmail.com)
* @extends {Response}
* @date 2016-06-16
* @version 1.1
* @since 0.1.0
*/
export default class UserStateResponse extends Response {
/**
* Constructor.
*
* @type {Object}
* @example
* r = new UserStateResponse({phone: '555-111-22-33'});
* console.log(r.type); // prints "user-state"
* console.log(r.phone); // prints "555-111-22-33"
*/
constructor(options) {
const opts = objectAssign({ type: 'user-state' }, options);
super(opts);
objectAssign(this, opts);
}
}
2 changes: 1 addition & 1 deletion src/validations/supported-response-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* console.log('response with type "something" is not supported');
* }
*/
export default new Set(['text', 'redirect', 'options', 'error']);
export default new Set(['text', 'redirect', 'options', 'error', 'user-state']);
15 changes: 15 additions & 0 deletions test/responses/user-state-response-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-new */
import test from 'ava';
import UserStateResponse from '../../src/responses/user-state-response';

test('can be constructed with default parameters', t => {
new UserStateResponse({ foo: 1 });
t.pass();
});

test('should save properties and have \'user-state\' type', t => {
const r = new UserStateResponse({ foo: 1, bar: 2 });
t.is(r.foo, 1);
t.is(r.bar, 2);
t.is(r.type, 'user-state');
});

0 comments on commit 3ef1811

Please sign in to comment.