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 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Import::GithubFailureSerializer, feature_category: :importers do
subject(:serializer) { described_class.new }
it 'represents GithubFailureEntity entities' do
expect(described_class.entity_class).to eq(Import::GithubFailureEntity)
end
describe '#represent' do
let(:timestamp) { Time.new(2023, 1, 1).utc }
let(:github_identifiers) { { 'iid' => 2, 'object_type' => 'pull_request', 'title' => 'Implement cool feature' } }
let(:project) do
instance_double(
Project,
id: 123456,
import_status: 'finished',
import_url: 'https://github.com/example/repo.git',
import_source: 'example/repo'
)
end
let(:import_failure) do
instance_double(
ImportFailure,
project: project,
exception_class: 'Some class',
exception_message: 'Something went wrong',
source: 'Gitlab::GithubImport::Importer::PullRequestImporter',
correlation_id_value: '2ea9c4b8587b6df49f35a3fb703688aa',
external_identifiers: github_identifiers,
created_at: timestamp
)
end
let(:expected_data) do
{
type: 'pull_request',
title: 'Implement cool feature',
provider_url: 'https://github.com/example/repo/pull/2',
details: {
exception_class: import_failure.exception_class,
exception_message: import_failure.exception_message,
correlation_id_value: import_failure.correlation_id_value,
source: import_failure.source,
github_identifiers: github_identifiers,
created_at: timestamp.iso8601(3)
}
}.deep_stringify_keys
end
context 'when a single object is being serialized' do
let(:resource) { import_failure }
it 'serializes import failure' do
expect(serializer.represent(resource).as_json).to eq expected_data
end
end
context 'when multiple objects are being serialized' do
let(:count) { 3 }
let(:resource) { Array.new(count, import_failure) }
it 'serializes array of import failures' do
expect(serializer.represent(resource).as_json).to all(eq(expected_data))
end
end
end
end
|