mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-15 13:45:25 +08:00
50 lines
1.6 KiB
Ruby
50 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'Api::V1::WrokflowsController', type: :request do
|
|
before :all do
|
|
@user = create(:user)
|
|
@teams = create_list(:team, 2, created_by: @user)
|
|
create(:user_team, user: @user, team: @teams.first, role: 2)
|
|
@valid_headers =
|
|
{ 'Authorization': 'Bearer ' + generate_token(@user.id) }
|
|
MyModuleStatusFlow.ensure_default
|
|
end
|
|
|
|
describe 'GET workflows, #index' do
|
|
it 'Response with correct workflows' do
|
|
hash_body = nil
|
|
get api_v1_workflows_path, headers: @valid_headers
|
|
expect { hash_body = json }.not_to raise_exception
|
|
expect(hash_body[:data]).to match(
|
|
ActiveModelSerializers::SerializableResource
|
|
.new(MyModuleStatusFlow.all,
|
|
each_serializer: Api::V1::WorkflowSerializer)
|
|
.as_json[:data]
|
|
)
|
|
end
|
|
end
|
|
|
|
describe 'GET worflow, #show' do
|
|
it 'When valid request' do
|
|
hash_body = nil
|
|
get api_v1_workflow_path(id: MyModuleStatusFlow.all.first), headers: @valid_headers
|
|
expect { hash_body = json }.not_to raise_exception
|
|
expect(hash_body[:data]).to match(
|
|
ActiveModelSerializers::SerializableResource
|
|
.new(MyModuleStatusFlow.all.first,
|
|
serializer: Api::V1::WorkflowSerializer)
|
|
.as_json[:data]
|
|
)
|
|
end
|
|
|
|
it 'When invalid request, non existing workflow' do
|
|
hash_body = nil
|
|
get api_v1_workflow_path(id: -1), headers: @valid_headers
|
|
expect(response).to have_http_status(404)
|
|
expect { hash_body = json }.not_to raise_exception
|
|
expect(hash_body['errors'][0]).to include('status': 404)
|
|
end
|
|
end
|
|
end
|