File: create_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (57 lines) | stat: -rw-r--r-- 1,740 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Creation of a machine learning model version', feature_category: :mlops do
  include GraphqlHelpers

  let_it_be(:model) { create(:ml_models) }
  let_it_be(:project) { model.project }
  let_it_be(:current_user) { project.owner }

  let(:version) { '1.0.0' }
  let(:description) { 'A description' }
  let(:input) { { project_path: project.full_path, modelId: model.to_gid, version: version, description: description } }
  let(:fields) do
    <<~FIELDS
    modelVersion{
      version
      description
      id
    }
    errors
    FIELDS
  end

  let(:mutation) { graphql_mutation(:ml_model_version_create, input, fields, ['version']) }
  let(:mutation_response) { graphql_mutation_response(:ml_model_version_create) }

  context 'when user is not allowed write changes' do
    before do
      allow(Ability).to receive(:allowed?).and_call_original
      allow(Ability).to receive(:allowed?)
                          .with(current_user, :write_model_registry, project)
                          .and_return(false)
    end

    it_behaves_like 'a mutation that returns a top-level access error'
  end

  context 'when user is allowed write changes' do
    it 'creates a model' do
      post_graphql_mutation(mutation, current_user: current_user)

      expect(response).to have_gitlab_http_status(:success)
      expect(mutation_response['modelVersion']).to include(
        'version' => version,
        'description' => description
      )
    end

    context 'when version is invalid' do
      let(:version) { 'invalid-version' }

      it_behaves_like 'a mutation that returns errors in the response', errors: ["Version must be semantic version"]
    end
  end
end