Enhance and test JSON schema for deployments

This commit is contained in:
Peter Leitzen 2018-10-10 11:43:02 +02:00
parent 75723034ce
commit 99a38a73a3
No known key found for this signature in database
GPG key ID: 97DE9D2E708A225E
3 changed files with 62 additions and 5 deletions

View file

@ -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
}

View file

@ -17,11 +17,10 @@
"author": {
"oneOf": [
{ "type": "null" },
{ "type": "user.json" }
{ "$ref": "user.json" }
]
}
},
"additionalProperties": false
}
}
]
}

View file

@ -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