2021-09-30 23:02:18 +05:30
|
|
|
import {
|
|
|
|
responseMessageFromSuccess,
|
|
|
|
responseMessageFromError,
|
|
|
|
} from '~/invite_members/utils/response_message_parser';
|
2021-11-18 22:05:49 +05:30
|
|
|
import { membersApiResponse, invitationsApiResponse } from '../mock_data/api_responses';
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
describe('Response message parser', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
const expectedMessage = 'expected display and message.';
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
describe('parse message from successful response', () => {
|
|
|
|
const exampleKeyedMsg = { 'email@example.com': expectedMessage };
|
2021-11-18 22:05:49 +05:30
|
|
|
const exampleFirstPartMultiple = 'username1: expected display and message.';
|
2021-09-30 23:02:18 +05:30
|
|
|
const exampleUserMsgMultiple =
|
2021-11-18 22:05:49 +05:30
|
|
|
' and username2: id not found and restricted email. and username3: email is restricted.';
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
it.each([
|
|
|
|
[[{ data: { message: expectedMessage } }]],
|
2021-11-18 22:05:49 +05:30
|
|
|
[[{ data: { message: exampleFirstPartMultiple + exampleUserMsgMultiple } }]],
|
2021-09-30 23:02:18 +05:30
|
|
|
[[{ data: { error: expectedMessage } }]],
|
|
|
|
[[{ data: { message: [expectedMessage] } }]],
|
|
|
|
[[{ data: { message: exampleKeyedMsg } }]],
|
|
|
|
])(`returns "${expectedMessage}" from success response: %j`, (successResponse) => {
|
|
|
|
expect(responseMessageFromSuccess(successResponse)).toBe(expectedMessage);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('message from error response', () => {
|
|
|
|
it.each([
|
|
|
|
[{ response: { data: { error: expectedMessage } } }],
|
|
|
|
[{ response: { data: { message: { user: [expectedMessage] } } } }],
|
|
|
|
[{ response: { data: { message: { access_level: [expectedMessage] } } } }],
|
|
|
|
[{ response: { data: { message: { error: expectedMessage } } } }],
|
|
|
|
[{ response: { data: { message: expectedMessage } } }],
|
|
|
|
])(`returns "${expectedMessage}" from error response: %j`, (errorResponse) => {
|
|
|
|
expect(responseMessageFromError(errorResponse)).toBe(expectedMessage);
|
|
|
|
});
|
|
|
|
});
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
describe('displaying only the first error when a response has messages for multiple users', () => {
|
|
|
|
const expected =
|
|
|
|
"The member's email address is not allowed for this project. Go to the Admin area > Sign-up restrictions, and check Allowed domains for sign-ups.";
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
[[{ data: membersApiResponse.MULTIPLE_USERS_RESTRICTED }]],
|
|
|
|
[[{ data: invitationsApiResponse.MULTIPLE_EMAIL_RESTRICTED }]],
|
|
|
|
[[{ data: invitationsApiResponse.EMAIL_RESTRICTED }]],
|
|
|
|
])(`returns "${expectedMessage}" from success response: %j`, (restrictedResponse) => {
|
|
|
|
expect(responseMessageFromSuccess(restrictedResponse)).toBe(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([[{ response: { data: membersApiResponse.SINGLE_USER_RESTRICTED } }]])(
|
|
|
|
`returns "${expectedMessage}" from error response: %j`,
|
|
|
|
(singleRestrictedResponse) => {
|
|
|
|
expect(responseMessageFromError(singleRestrictedResponse)).toBe(expected);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|