diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-05-03 23:11:55 +0200 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2019-05-07 23:15:36 +0200 |
commit | 0625ccc652f97310b2444bb16ed8e20ee0642300 (patch) | |
tree | b6f725d40fc0ce39b8a660e29c440feb8e6e2137 /spec/javascripts/notes | |
parent | 9d4450263fd7dc53dafd62389871d8b1fcea5e1a (diff) | |
download | gitlab-ce-0625ccc652f97310b2444bb16ed8e20ee0642300.tar.gz |
Add failing test for saveNote error handling
Diffstat (limited to 'spec/javascripts/notes')
-rw-r--r-- | spec/javascripts/notes/stores/actions_spec.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/javascripts/notes/stores/actions_spec.js b/spec/javascripts/notes/stores/actions_spec.js index 39901276b8c..7a9f32ddcff 100644 --- a/spec/javascripts/notes/stores/actions_spec.js +++ b/spec/javascripts/notes/stores/actions_spec.js @@ -794,6 +794,51 @@ describe('Actions Notes Store', () => { }); }); + describe('saveNote', () => { + const payload = { endpoint: TEST_HOST, data: { 'note[note]': 'some text' } }; + + describe('if response contains errors', () => { + const res = { errors: { something: ['went wrong'] } }; + + it('throws an error', done => { + actions + .saveNote( + { + commit() {}, + dispatch: () => Promise.resolve(res), + }, + payload, + ) + .then(() => done.fail('Expected error to be thrown!')) + .catch(error => { + expect(error.message).toBe('Failed to save comment!'); + }) + .then(done) + .catch(done.fail); + }); + }); + + describe('if response contains no errors', () => { + const res = { valid: true }; + + it('returns the response', done => { + actions + .saveNote( + { + commit() {}, + dispatch: () => Promise.resolve(res), + }, + payload, + ) + .then(data => { + expect(data).toBe(res); + }) + .then(done) + .catch(done.fail); + }); + }); + }); + describe('submitSuggestion', () => { const discussionId = 'discussion-id'; const noteId = 'note-id'; |