Skip to content
Snippets Groups Projects
Verified Commit 04a96dd9 authored by Justin Ho Tuan Duong's avatar Justin Ho Tuan Duong Committed by GitLab
Browse files

Merge branch '499871-fixtures-for-container-protection-tag-rules' into 'master'

Use fixtures for container protection tag rules spec

See merge request !176689



Merged-by: default avatarJustin Ho Tuan Duong <hduong@gitlab.com>
Approved-by: Tan Le's avatarTan Le <tle@gitlab.com>
Approved-by: default avatarJustin Ho Tuan Duong <hduong@gitlab.com>
Reviewed-by: default avatarJustin Ho Tuan Duong <hduong@gitlab.com>
Reviewed-by: default avatarRahul Chanila <rchanila@gitlab.com>
Co-authored-by: default avatarRahul Chanila <rchanila@gitlab.com>
parents 42b432e1 ccc6b3c2
No related branches found
No related tags found
3 merge requests!181325Fix ambiguous `created_at` in project.rb,!179611Draft: Rebase CR approach for zoekt assignments,!176689Use fixtures for container protection tag rules spec
Pipeline #1612708696 passed
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Container registry (JavaScript fixtures)', feature_category: :container_registry do
include GraphqlHelpers
include JavaScriptFixturesHelpers
describe GraphQL::Query, type: :request do
let_it_be(:group) { create(:group, path: 'container-registry-group') }
let_it_be(:project) { create(:project, group: group, path: 'container-registry-project') }
let_it_be(:owner) { create(:user) }
let_it_be(:user) { create(:user) }
before_all do
project.add_owner(owner)
end
describe 'Protected container image tags' do
project_container_protection_tag_rules_query_path =
'packages_and_registries/settings/project/graphql/queries/get_container_protection_tag_rules.query.graphql'
context 'when user does not have access to the project' do
it "graphql/#{project_container_protection_tag_rules_query_path}.null_project.json" do
query = get_graphql_query_as_string(project_container_protection_tag_rules_query_path)
post_graphql(query, current_user: user, variables: { projectPath: project.full_path, first: 5 })
expect_graphql_errors_to_be_empty
end
end
context 'when user has access to the project &' do
context 'with no tag protection rules' do
it "graphql/#{project_container_protection_tag_rules_query_path}.empty_rules.json" do
query = get_graphql_query_as_string(project_container_protection_tag_rules_query_path)
post_graphql(query, current_user: owner, variables: { projectPath: project.full_path, first: 5 })
expect_graphql_errors_to_be_empty
end
end
context 'with tag protection rules' do
let_it_be(:container_protection_tag_rule) do
create(:container_registry_protection_tag_rule,
project: project,
minimum_access_level_for_push: Gitlab::Access::MAINTAINER,
minimum_access_level_for_delete: Gitlab::Access::OWNER
)
end
it "graphql/#{project_container_protection_tag_rules_query_path}.json" do
query = get_graphql_query_as_string(project_container_protection_tag_rules_query_path)
post_graphql(query, current_user: owner, variables: { projectPath: project.full_path, first: 5 })
expect_graphql_errors_to_be_empty
end
end
end
end
end
end
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { GlAlert, GlBadge, GlLoadingIcon, GlSprintf, GlTableLite } from '@gitlab/ui';
import containerProtectionTagRuleEmptyRulesQueryPayload from 'test_fixtures/graphql/packages_and_registries/settings/project/graphql/queries/get_container_protection_tag_rules.query.graphql.empty_rules.json';
import containerProtectionTagRuleNullProjectQueryPayload from 'test_fixtures/graphql/packages_and_registries/settings/project/graphql/queries/get_container_protection_tag_rules.query.graphql.null_project.json';
import containerProtectionTagRuleQueryPayload from 'test_fixtures/graphql/packages_and_registries/settings/project/graphql/queries/get_container_protection_tag_rules.query.graphql.json';
import createMockApollo from 'helpers/mock_apollo_helper';
import {
mountExtended,
......@@ -13,7 +16,6 @@ import ContainerProtectionTagRules, {
MinimumAccessLevelOptions,
} from '~/packages_and_registries/settings/project/components/container_protection_tag_rules.vue';
import getContainerProtectionTagRulesQuery from '~/packages_and_registries/settings/project/graphql/queries/get_container_protection_tag_rules.query.graphql';
import { containerProtectionTagRuleQueryPayload } from '../mock_data';
Vue.use(VueApollo);
......@@ -38,7 +40,7 @@ describe('ContainerProtectionTagRules', () => {
provide = defaultProvidedValues,
containerProtectionTagRuleQueryResolver = jest
.fn()
.mockResolvedValue(containerProtectionTagRuleQueryPayload()),
.mockResolvedValue(containerProtectionTagRuleQueryPayload),
} = {}) => {
const requestHandlers = [
[getContainerProtectionTagRulesQuery, containerProtectionTagRuleQueryResolver],
......@@ -84,7 +86,7 @@ describe('ContainerProtectionTagRules', () => {
it('calls graphql api query', () => {
const containerProtectionTagRuleQueryResolver = jest
.fn()
.mockResolvedValue(containerProtectionTagRuleQueryPayload());
.mockResolvedValue(containerProtectionTagRuleQueryPayload);
createComponent({ containerProtectionTagRuleQueryResolver });
expect(containerProtectionTagRuleQueryResolver).toHaveBeenCalledWith(
......@@ -105,7 +107,7 @@ describe('ContainerProtectionTagRules', () => {
});
it('shows count badge', () => {
expect(findBadge().text()).toMatchInterpolatedText('5 of 5');
expect(findBadge().text()).toMatchInterpolatedText('1 of 5');
});
it('shows table', () => {
......@@ -150,7 +152,7 @@ describe('ContainerProtectionTagRules', () => {
});
it('with container protection tag rules', () => {
containerProtectionTagRuleQueryPayload().data.project.containerProtectionTagRules.nodes.forEach(
containerProtectionTagRuleQueryPayload.data.project.containerProtectionTagRules.nodes.forEach(
(protectionRule, i) => {
expect(findTableRowCell(i, 0).text()).toBe(protectionRule.tagNamePattern);
expect(findTableRowCell(i, 1).text()).toBe(
......@@ -165,12 +167,13 @@ describe('ContainerProtectionTagRules', () => {
});
});
describe('when data is loaded & is empty', () => {
describe.each([
['project does not contain any rules', containerProtectionTagRuleEmptyRulesQueryPayload],
['project is null', containerProtectionTagRuleNullProjectQueryPayload],
])('when data is loaded & %s', (_, payload) => {
beforeEach(async () => {
createComponent({
containerProtectionTagRuleQueryResolver: jest
.fn()
.mockResolvedValue(containerProtectionTagRuleQueryPayload({ nodes: [] })),
containerProtectionTagRuleQueryResolver: jest.fn().mockResolvedValue(payload),
});
await waitForPromises();
});
......
......@@ -265,40 +265,3 @@ export const updateContainerProtectionRepositoryRuleMutationPayload = ({
},
},
});
export const containerProtectionTagRulesData = [
...Array.from(Array(4)).map((_e, i) => ({
id: `gid://gitlab/ContainerRegistry::Protection::TagRule/${i}`,
tagNamePattern: `@flight/flight/maintainer-${i}-*`,
minimumAccessLevelForPush: 'MAINTAINER',
minimumAccessLevelForDelete: 'ADMIN',
})),
{
id: 'gid://gitlab/ContainerRegistry::Protection::TagRule/5',
tagNamePattern: '@flight/flight/owner-5-*',
minimumAccessLevelForPush: 'OWNER',
minimumAccessLevelForDelete: 'OWNER',
},
];
export const containerProtectionTagRuleQueryPayload = ({
errors = [],
nodes = containerProtectionTagRulesData,
pageInfo = {
hasNextPage: false,
hasPreviousPage: false,
startCursor: '0',
endCursor: '10',
},
} = {}) => ({
data: {
project: {
id: '1',
containerProtectionTagRules: {
nodes,
pageInfo: { __typename: 'PageInfo', ...pageInfo },
},
errors,
},
},
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment