From 99a38a73a3f1f8d817e43c96ff20337a6832cc21 Mon Sep 17 00:00:00 2001 From: Peter Leitzen Date: Wed, 10 Oct 2018 11:43:02 +0200 Subject: Enhance and test JSON schema for deployments --- spec/fixtures/api/schemas/deployment.json | 27 ++++++++++++++++++-- spec/fixtures/api/schemas/entities/commit.json | 5 ++-- spec/serializers/deployment_serializer_spec.rb | 35 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 spec/serializers/deployment_serializer_spec.rb (limited to 'spec') diff --git a/spec/fixtures/api/schemas/deployment.json b/spec/fixtures/api/schemas/deployment.json index 8c8cdf8bcb2..44835386cfc 100644 --- a/spec/fixtures/api/schemas/deployment.json +++ b/spec/fixtures/api/schemas/deployment.json @@ -20,12 +20,35 @@ "name" ], "properties": { - "name": { "type": "string" } + "name": { "type": "string" }, + "ref_path": { "type": "string" } }, "additionalProperties": false }, "sha": { "type": "string" }, - "tag": { "type": "boolean" } + "tag": { "type": "boolean" }, + "user": { + "oneOf": [ + { "type": "null" }, + { "$ref": "entities/user.json" } + ] + }, + "commit": { + "oneOf": [ + { "type": "null" }, + { "$ref": "entities/commit.json" } + ] + }, + "deployable": { + "oneOf": [ + { "type": "null" }, + { "$ref": "job/job.json" } + ] + }, + "manual_actions": { + "type": "array", + "items": { "$ref": "job/job.json" } + } }, "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/entities/commit.json b/spec/fixtures/api/schemas/entities/commit.json index 686d29c97d2..324702e3f94 100644 --- a/spec/fixtures/api/schemas/entities/commit.json +++ b/spec/fixtures/api/schemas/entities/commit.json @@ -17,11 +17,10 @@ "author": { "oneOf": [ { "type": "null" }, - { "type": "user.json" } + { "$ref": "user.json" } ] } - }, - "additionalProperties": false + } } ] } diff --git a/spec/serializers/deployment_serializer_spec.rb b/spec/serializers/deployment_serializer_spec.rb new file mode 100644 index 00000000000..4834f5ede3c --- /dev/null +++ b/spec/serializers/deployment_serializer_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DeploymentSerializer do + set(:project) { create(:project, :repository) } + set(:user) { create(:user, email: project.commit.author_email) } + + let(:resource) { create(:deployment, project: project, sha: project.commit.id) } + let(:serializer) { described_class.new(request) } + + shared_examples 'json schema' do + let(:json_entity) { subject.as_json } + + it 'matches deployment entity schema' do + expect(json_entity).to match_schema('deployment') + end + end + + describe '#represent' do + subject { serializer.represent(resource) } + + let(:request) { { project: project, current_user: user } } + + it_behaves_like 'json schema' + end + + describe '#represent_concise' do + subject { serializer.represent_concise(resource) } + + let(:request) { { project: project } } + + it_behaves_like 'json schema' + end +end -- cgit v1.2.3