summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2019-05-03 23:11:55 +0200
committerWinnie Hellmann <winnie@gitlab.com>2019-05-07 23:15:36 +0200
commit0625ccc652f97310b2444bb16ed8e20ee0642300 (patch)
treeb6f725d40fc0ce39b8a660e29c440feb8e6e2137
parent9d4450263fd7dc53dafd62389871d8b1fcea5e1a (diff)
downloadgitlab-ce-0625ccc652f97310b2444bb16ed8e20ee0642300.tar.gz
Add failing test for saveNote error handling
-rw-r--r--spec/javascripts/notes/stores/actions_spec.js45
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';