Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils_spec.js « notes « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0882e0a57596a765b15ef64cc64421654897b461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { sprintf } from '~/locale';
import { getErrorMessages } from '~/notes/utils';
import { HTTP_STATUS_UNPROCESSABLE_ENTITY, HTTP_STATUS_BAD_REQUEST } from '~/lib/utils/http_status';
import { COMMENT_FORM } from '~/notes/i18n';

describe('getErrorMessages', () => {
  describe('when http status is not HTTP_STATUS_UNPROCESSABLE_ENTITY', () => {
    it('returns generic error', () => {
      const errorMessages = getErrorMessages(
        { errors: ['unknown error'] },
        HTTP_STATUS_BAD_REQUEST,
      );

      expect(errorMessages).toStrictEqual([COMMENT_FORM.GENERIC_UNSUBMITTABLE_NETWORK]);
    });
  });

  describe('when http status is HTTP_STATUS_UNPROCESSABLE_ENTITY', () => {
    it('returns all errors', () => {
      const errorMessages = getErrorMessages(
        { errors: 'error 1 and error 2' },
        HTTP_STATUS_UNPROCESSABLE_ENTITY,
      );

      expect(errorMessages).toStrictEqual([
        sprintf(COMMENT_FORM.error, { reason: 'error 1 and error 2' }),
      ]);
    });

    describe('when response contains commands_only errors', () => {
      it('only returns commands_only errors', () => {
        const errorMessages = getErrorMessages(
          {
            errors: {
              commands_only: ['commands_only error 1', 'commands_only error 2'],
              base: ['base error 1'],
            },
          },
          HTTP_STATUS_UNPROCESSABLE_ENTITY,
        );

        expect(errorMessages).toStrictEqual(['commands_only error 1', 'commands_only error 2']);
      });
    });
  });
});