-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add decorator for released versions
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
lib/pact_broker/api/decorators/released_versions_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'pact_broker/api/decorators/base_decorator' | ||
require 'pact_broker/api/decorators/released_version_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class ReleasedVersionsDecorator < BaseDecorator | ||
collection :entries, as: :releasedVersions, embedded: true, :extend => PactBroker::Api::Decorators::ReleasedVersionDecorator | ||
|
||
link :self do | context | | ||
href = append_query_if_present(context[:resource_url], context[:query_string]) | ||
{ | ||
href: href, | ||
title: context.fetch(:title) | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
spec/features/get_released_versions_for_version_and_environment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
RSpec.describe "Get released versions for version and environment" do | ||
let!(:version) { td.create_consumer("Foo").create_consumer_version("1").and_return(:consumer_version) } | ||
let!(:test_environment) { td.create_environment("test").and_return(:environment) } | ||
let!(:prod_environment) { td.create_environment("prod").and_return(:environment) } | ||
let!(:deployed_version) do | ||
td.create_released_version_for_consumer_version(environment_name: "test", created_at: DateTime.now - 2) | ||
.create_deployed_version_for_consumer_version(environment_name: "prod", created_at: DateTime.now - 1) | ||
end | ||
|
||
let(:path) do | ||
PactBroker::Api::PactBrokerUrls.released_versions_for_version_and_environment_url( | ||
version, | ||
test_environment | ||
) | ||
end | ||
|
||
let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) } | ||
|
||
subject { get(path, nil, { "HTTP_ACCEPT" => "application/hal+json" }) } | ||
|
||
it "returns a list of released versions" do | ||
expect(response_body_hash[:_embedded][:releasedVersions]).to be_a(Array) | ||
expect(response_body_hash[:_embedded][:releasedVersions].size).to eq 1 | ||
expect(response_body_hash[:_links][:self][:title]).to eq "Released versions for Foo version 1 in Test" | ||
expect(response_body_hash[:_links][:self][:href]).to end_with(path) | ||
end | ||
end |