Skip to content
代码片段 群组 项目
未验证 提交 79d4f28b 编辑于 作者: Artur Fedorov's avatar Artur Fedorov 提交者: GitLab
浏览文件

Merge branch '416903-update-project-modal-errors' into 'master'

No related branches found
No related tags found
无相关合并请求
......@@ -42,11 +42,3 @@ export const EMPTY_LIST_DESCRIPTION = s__(
export const EMPTY_POLICY_PROJECT_DESCRIPTION = s__(
'SecurityOrchestration|This %{namespaceType} is not linked to a security policy project',
);
export const POLICY_PROJECT_LINK_SUCCESS_MESSAGE = s__(
'SecurityOrchestration|Security policy project was linked successfully',
);
export const POLICY_PROJECT_LINK_ERROR_MESSAGE = s__(
'SecurityOrchestration|An error occurred assigning your security policy project',
);
......@@ -4,10 +4,6 @@ import { s__, __ } from '~/locale';
import linkSecurityPolicyProject from '../../graphql/mutations/link_security_policy_project.mutation.graphql';
import unlinkSecurityPolicyProject from '../../graphql/mutations/unlink_security_policy_project.mutation.graphql';
import InstanceProjectSelector from './instance_project_selector.vue';
import {
POLICY_PROJECT_LINK_ERROR_MESSAGE,
POLICY_PROJECT_LINK_SUCCESS_MESSAGE,
} from './constants';
export default {
i18n: {
......@@ -16,9 +12,11 @@ export default {
header: s__('SecurityOrchestration|Select security project'),
},
save: {
okLink: POLICY_PROJECT_LINK_SUCCESS_MESSAGE,
okLink: s__('SecurityOrchestration|Security policy project was linked successfully'),
okUnlink: s__('SecurityOrchestration|Security policy project was unlinked successfully'),
errorLink: POLICY_PROJECT_LINK_ERROR_MESSAGE,
errorLink: s__(
'SecurityOrchestration|An error occurred assigning your security policy project',
),
errorUnlink: s__(
'SecurityOrchestration|An error occurred unassigning your security policy project',
),
......@@ -98,9 +96,11 @@ export default {
variant: 'success',
hasPolicyProject: true,
});
} catch {
} catch (e) {
const text = e?.message || this.$options.i18n.save.errorLink;
this.$emit('project-updated', {
text: this.$options.i18n.save.errorLink,
text,
variant: 'danger',
hasPolicyProject: false,
});
......@@ -129,9 +129,11 @@ export default {
variant: 'success',
hasPolicyProject: false,
});
} catch {
} catch (e) {
const text = e?.message || this.$options.i18n.save.errorUnlink;
this.$emit('project-updated', {
text: this.$options.i18n.save.errorUnlink,
text,
variant: 'danger',
hasPolicyProject: true,
});
......
......@@ -9,10 +9,6 @@ import ProjectModal from 'ee/security_orchestration/components/policies/project_
import linkSecurityPolicyProject from 'ee/security_orchestration/graphql/mutations/link_security_policy_project.mutation.graphql';
import unlinkSecurityPolicyProject from 'ee/security_orchestration/graphql/mutations/unlink_security_policy_project.mutation.graphql';
import InstanceProjectSelector from 'ee/security_orchestration/components/policies/instance_project_selector.vue';
import {
POLICY_PROJECT_LINK_ERROR_MESSAGE,
POLICY_PROJECT_LINK_SUCCESS_MESSAGE,
} from 'ee/security_orchestration/components/policies/constants';
import {
mockLinkSecurityPolicyProjectResponses,
mockUnlinkSecurityPolicyProjectResponses,
......@@ -122,9 +118,9 @@ describe('ProjectModal Component', () => {
'Unlinking a security project removes all policies stored in the linked security project. Save to confirm this action.';
it.each`
mutationResult | expectedVariant | expectedText | expectedHasPolicyProject
${'success'} | ${'success'} | ${'Security policy project was unlinked successfully'} | ${false}
${'failure'} | ${'danger'} | ${'An error occurred unassigning your security policy project'} | ${true}
mutationResult | expectedVariant | expectedText | expectedHasPolicyProject
${'success'} | ${'success'} | ${'Security policy project was unlinked successfully'} | ${false}
${'failure'} | ${'danger'} | ${'unlink failed'} | ${true}
`(
'unlinks a project and handles $mutationResult case',
async ({ mutationResult, expectedVariant, expectedText, expectedHasPolicyProject }) => {
......@@ -182,9 +178,9 @@ describe('ProjectModal Component', () => {
});
it.each`
messageType | factoryFn | text | variant | hasPolicyProject | selectedProject
${'success'} | ${createWrapperAndSelectProject} | ${POLICY_PROJECT_LINK_SUCCESS_MESSAGE} | ${'success'} | ${true} | ${sampleProject}
${'failure'} | ${() => createWrapperAndSelectProject({ mutationResult: mockLinkSecurityPolicyProjectResponses.failure })} | ${POLICY_PROJECT_LINK_ERROR_MESSAGE} | ${'danger'} | ${false} | ${undefined}
messageType | factoryFn | text | variant | hasPolicyProject | selectedProject
${'success'} | ${createWrapperAndSelectProject} | ${'Security policy project was linked successfully'} | ${'success'} | ${true} | ${sampleProject}
${'failure'} | ${() => createWrapperAndSelectProject({ mutationResult: mockLinkSecurityPolicyProjectResponses.failure })} | ${'link failed'} | ${'danger'} | ${false} | ${undefined}
`(
'emits an event with $messageType message',
async ({ factoryFn, text, variant, hasPolicyProject, selectedProject }) => {
......
......@@ -57,13 +57,13 @@ export const mockLinkSecurityPolicyProjectResponses = {
success: jest.fn().mockResolvedValue({ data: { securityPolicyProjectAssign: { errors: [] } } }),
failure: jest
.fn()
.mockResolvedValue({ data: { securityPolicyProjectAssign: { errors: ['mutation failed'] } } }),
.mockResolvedValue({ data: { securityPolicyProjectAssign: { errors: ['link failed'] } } }),
};
export const mockUnlinkSecurityPolicyProjectResponses = {
success: jest.fn().mockResolvedValue({ data: { securityPolicyProjectUnassign: { errors: [] } } }),
failure: jest.fn().mockResolvedValue({
data: { securityPolicyProjectUnassign: { errors: ['mutation failed'] } },
data: { securityPolicyProjectUnassign: { errors: ['unlink failed'] } },
}),
};
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册