|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +RSpec.describe 'namespacesProjectsFlowsExecutionResult Subscription', type: :channel do |
| 6 | + include AuthenticationHelpers |
| 7 | + include ActionCable::Channel::TestCase::Behavior |
| 8 | + |
| 9 | + include_context 'with graphql subscription support' |
| 10 | + |
| 11 | + tests GraphqlChannel |
| 12 | + |
| 13 | + let(:user) { create(:user) } |
| 14 | + let(:token) { "Session #{authorization_token(user)}" } |
| 15 | + let(:flow) { create(:flow) } |
| 16 | + let(:execution_identifier) { 'existing-execution' } |
| 17 | + |
| 18 | + let(:subscription_query) do |
| 19 | + <<~GQL |
| 20 | + subscription($executionIdentifier: String!) { |
| 21 | + namespacesProjectsFlowsExecutionResult(executionIdentifier: $executionIdentifier) { |
| 22 | + executionResult { success } |
| 23 | + } |
| 24 | + } |
| 25 | + GQL |
| 26 | + end |
| 27 | + |
| 28 | + before do |
| 29 | + create(:namespace_member, namespace: flow.project.namespace, user: user) |
| 30 | + stub_allowed_ability(NamespaceProjectPolicy, :read_namespace_project, user: user, subject: flow.project) |
| 31 | + |
| 32 | + subscribe(token: token) |
| 33 | + end |
| 34 | + |
| 35 | + context 'when the execution result already exists' do |
| 36 | + before do |
| 37 | + create(:execution_result, flow: flow, execution_identifier: execution_identifier, success: { 'done' => true }) |
| 38 | + end |
| 39 | + |
| 40 | + it 'immediately delivers the result in the initial subscription response' do |
| 41 | + perform :execute, query: subscription_query, variables: { executionIdentifier: execution_identifier } |
| 42 | + |
| 43 | + result = transmissions.last |
| 44 | + expect(result.dig('result', 'data', 'namespacesProjectsFlowsExecutionResult', 'executionResult', 'success')) |
| 45 | + .to eq({ 'done' => true }) |
| 46 | + end |
| 47 | + end |
| 48 | +end |
0 commit comments