File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -68,4 +68,17 @@ describe('Concepts', () => {
6868 } )
6969 . catch ( errorHandler . bind ( done ) ) ;
7070 } ) ;
71+
72+ it ( 'updates a concept name' , done => {
73+ const originalName = conceptsIds [ 0 ] ;
74+ const newName = `${ originalName } -newName` ;
75+
76+ app . concepts . update ( { id : originalName , name : newName } )
77+ . then ( concepts => {
78+ expect ( concepts [ 0 ] . id ) . toBe ( originalName ) ;
79+ expect ( concepts [ 0 ] . name ) . toBe ( newName ) ;
80+ done ( ) ;
81+ } )
82+ . catch ( errorHandler . bind ( done ) ) ;
83+ } ) ;
7184} ) ;
Original file line number Diff line number Diff line change @@ -119,7 +119,38 @@ class Concepts {
119119 } ) ;
120120 } ) ;
121121 }
122- }
123- ;
122+
123+ /**
124+ * Update a concepts
125+ * @param {object|object[] } concepts Can be a single concept object or an array of concept objects
126+ * @param {object } concepts[].concept A concept object with the following attributes
127+ * @param {object } concepts[].concept.id The concept's id (Required)
128+ * @param {object } concepts[].concept.name The concept's new name
129+ * @param {string } [action=overwrite] The action to use for the PATCH
130+ * @return {Promise(Concepts, error) } A Promise that is fulfilled with a Concepts instance or rejected with an error
131+ */
132+ update ( concepts = [ ] , action = 'overwrite' ) {
133+ if ( ! checkType ( / A r r a y / , concepts ) ) {
134+ concepts = [ concepts ] ;
135+ }
136+ const data = {
137+ concepts,
138+ action
139+ } ;
140+ const url = `${ this . _config . basePath } ${ CONCEPTS_PATH } ` ;
141+ return wrapToken ( this . _config , headers => {
142+ return new Promise ( ( resolve , reject ) => {
143+ axios . patch ( url , data , { headers } )
144+ . then ( ( response ) => {
145+ if ( isSuccess ( response ) ) {
146+ resolve ( new Concepts ( this . _config , response . data . concepts ) ) ;
147+ } else {
148+ reject ( response ) ;
149+ }
150+ } , reject ) ;
151+ } ) ;
152+ } ) ;
153+ }
154+ } ;
124155
125156module . exports = Concepts ;
You can’t perform that action at this time.
0 commit comments