gds-api-adapters 30.3.0 → 30.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ea4fb424e88b660a8ecb6ea9a088abf135983aa
4
- data.tar.gz: ff6e5fd6357f9078dbc63762f498e3c47fc4d0d8
3
+ metadata.gz: 45470b12b8841677669e769a1cda10981a25d5ad
4
+ data.tar.gz: 0c32f6ac9fca548e90072e70597d3227b9697a6f
5
5
  SHA512:
6
- metadata.gz: 396bb7e3cddb5f262656439e1ef8c52795fa8b76f54e2339875e9d7d9ecd3e81843af9fdd8b1e050e9ca7293e22ee60b7af0078b7787235005f32fd972965ced
7
- data.tar.gz: 173c4784e54d85ffdb1b6411572283a4082a5344cf0bb5b5ea87c6dabf500eef4b19963f6d26dc80109463bc9610d889eef7e5e757062de761f4c5f9810a2330
6
+ metadata.gz: e8340c617333eb1810e1e46ef72bed25ac8cc080c65325c2e375dc71790d1ad8781a3582ed4abca59508a1b940cdbe1a83e3c6966a2673ceb7c65fc81b29d504
7
+ data.tar.gz: 160d311984d37bfa2992313be1d240a898005b8063b95448ad420f3d0da40d2dfb03d73691ab75a6fa9f4f66735e2a1fe6429c123af95c2e65ad933bf995fda2
@@ -107,6 +107,32 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
107
107
  post_json!(publish_url(content_id), params)
108
108
  end
109
109
 
110
+ # Unpublish a content item
111
+ #
112
+ # The publishing API will "unpublish" a live item, to remove it from the public
113
+ # site, or update an existing unpublishing.
114
+ #
115
+ # @param content_id [UUID]
116
+ # @param type [String] Either 'withdrawal', 'gone' or 'redirect'.
117
+ # @param explanation [String] (optional) Text to show on the page.
118
+ # @param alternative_path [String] (optional) Alternative path to show on the page or redirect to.
119
+ # @param discard_drafts [Boolean] (optional) Whether to discard drafts on that item. Defaults to false.
120
+ # @param previous_version [Integer] (optional) A lock version number for optimistic locking.
121
+ #
122
+ # @see TODO
123
+ def unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, previous_version: nil)
124
+ params = {
125
+ type: type
126
+ }
127
+
128
+ params.merge!(explanation: explanation) if explanation
129
+ params.merge!(alternative_path: alternative_path) if alternative_path
130
+ params.merge!(previous_version: previous_version) if previous_version
131
+ params.merge!(discard_drafts: discard_drafts) if discard_drafts
132
+
133
+ post_json!(unpublish_url(content_id), params)
134
+ end
135
+
110
136
  # Discard a draft
111
137
  #
112
138
  # Deletes the draft content item.
@@ -213,6 +239,11 @@ private
213
239
  "#{endpoint}/v2/content/#{content_id}/publish"
214
240
  end
215
241
 
242
+ def unpublish_url(content_id)
243
+ validate_content_id(content_id)
244
+ "#{endpoint}/v2/content/#{content_id}/unpublish"
245
+ end
246
+
216
247
  def discard_url(content_id)
217
248
  validate_content_id(content_id)
218
249
  "#{endpoint}/v2/content/#{content_id}/discard-draft"
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '30.3.0'
2
+ VERSION = '30.4.0'
3
3
  end
@@ -141,7 +141,7 @@ describe GdsApi::PublishingApiV2 do
141
141
  end
142
142
 
143
143
  describe "optimistic locking" do
144
- describe "if the content item has not change since it was requested" do
144
+ describe "if the content item has not changed since it was requested" do
145
145
  before do
146
146
  @content_item = content_item_for_content_id(@content_id, "previous_version" => 3)
147
147
 
@@ -471,7 +471,7 @@ describe GdsApi::PublishingApiV2 do
471
471
  end
472
472
 
473
473
  describe "optimistic locking" do
474
- describe "if the content item has not change since it was requested" do
474
+ describe "if the content item has not changed since it was requested" do
475
475
  before do
476
476
  publishing_api
477
477
  .given("the content item #{@content_id} is at version 3")
@@ -542,6 +542,197 @@ describe GdsApi::PublishingApiV2 do
542
542
  end
543
543
  end
544
544
 
545
+ describe "#unpublish" do
546
+ describe "if the unpublish command succeeds" do
547
+ before do
548
+ publishing_api
549
+ .given("a published content item exists with content_id: #{@content_id}")
550
+ .upon_receiving("an unpublish request")
551
+ .with(
552
+ method: :post,
553
+ path: "/v2/content/#{@content_id}/unpublish",
554
+ body: {
555
+ type: "gone",
556
+ },
557
+ headers: {
558
+ "Content-Type" => "application/json",
559
+ },
560
+ )
561
+ .will_respond_with(
562
+ status: 200
563
+ )
564
+ end
565
+
566
+ it "responds with 200" do
567
+ response = @api_client.unpublish(@content_id, type: "gone")
568
+ assert_equal 200, response.code
569
+ end
570
+ end
571
+
572
+ describe "if the content item does not exist" do
573
+ before do
574
+ publishing_api
575
+ .given("no content exists")
576
+ .upon_receiving("an unpublish request")
577
+ .with(
578
+ method: :post,
579
+ path: "/v2/content/#{@content_id}/unpublish",
580
+ body: {
581
+ type: "gone",
582
+ },
583
+ headers: {
584
+ "Content-Type" => "application/json",
585
+ },
586
+ )
587
+ .will_respond_with(
588
+ status: 404
589
+ )
590
+ end
591
+
592
+ it "responds with 404" do
593
+ error = assert_raises GdsApi::HTTPClientError do
594
+ @api_client.unpublish(@content_id, type: "gone")
595
+ end
596
+
597
+ assert_equal 404, error.code
598
+ end
599
+ end
600
+
601
+ describe "if the type is incorrect" do
602
+ before do
603
+ publishing_api
604
+ .given("a published content item exists with content_id: #{@content_id}")
605
+ .upon_receiving("an invalid unpublish request")
606
+ .with(
607
+ method: :post,
608
+ path: "/v2/content/#{@content_id}/unpublish",
609
+ body: {
610
+ type: "not-a-valid-type",
611
+ },
612
+ headers: {
613
+ "Content-Type" => "application/json",
614
+ },
615
+ )
616
+ .will_respond_with(
617
+ status: 422,
618
+ body: {
619
+ "error" => {
620
+ "code" => 422,
621
+ "message" => Pact.term(generate: "not-a-valid-type is not a valid unpublishing type", matcher:/\S+/),
622
+ "fields" => {},
623
+ },
624
+ }
625
+ )
626
+ end
627
+
628
+ it "responds with 422" do
629
+ error = assert_raises GdsApi::HTTPClientError do
630
+ @api_client.unpublish(@content_id, type: "not-a-valid-type")
631
+ end
632
+
633
+ assert_equal 422, error.code
634
+ assert_equal "not-a-valid-type is not a valid unpublishing type", error.error_details["error"]["message"]
635
+ end
636
+ end
637
+
638
+ describe "if the content item is already unpublished" do
639
+ before do
640
+ publishing_api
641
+ .given("an unpublished content item exists with content_id: #{@content_id}")
642
+ .upon_receiving("an unpublish request")
643
+ .with(
644
+ method: :post,
645
+ path: "/v2/content/#{@content_id}/unpublish",
646
+ body: {
647
+ type: "gone",
648
+ },
649
+ headers: {
650
+ "Content-Type" => "application/json",
651
+ },
652
+ )
653
+ .will_respond_with(
654
+ status: 200
655
+ )
656
+ end
657
+
658
+ it "responds with 200 and updates the unpublishing" do
659
+ response = @api_client.unpublish(@content_id, type: "gone")
660
+ assert_equal 200, response.code
661
+ end
662
+ end
663
+
664
+ describe "optimistic locking" do
665
+ describe "if the content item has not changed since it was requested" do
666
+ before do
667
+ publishing_api
668
+ .given("the published content item #{@content_id} is at version 3")
669
+ .upon_receiving("an unpublish request for version 3")
670
+ .with(
671
+ method: :post,
672
+ path: "/v2/content/#{@content_id}/unpublish",
673
+ body: {
674
+ type: "gone",
675
+ previous_version: 3,
676
+ },
677
+ headers: {
678
+ "Content-Type" => "application/json",
679
+ },
680
+ )
681
+ .will_respond_with(
682
+ status: 200,
683
+ )
684
+ end
685
+
686
+ it "responds with 200 OK" do
687
+ response = @api_client.unpublish(@content_id, type: "gone", previous_version: 3)
688
+ assert_equal 200, response.code
689
+ end
690
+ end
691
+
692
+ describe "if the content item has changed in the meantime" do
693
+ before do
694
+ publishing_api
695
+ .given("the published content item #{@content_id} is at version 3")
696
+ .upon_receiving("an unpublish request for version 2")
697
+ .with(
698
+ method: :post,
699
+ path: "/v2/content/#{@content_id}/unpublish",
700
+ body: {
701
+ type: "gone",
702
+ previous_version: 2,
703
+ },
704
+ headers: {
705
+ "Content-Type" => "application/json",
706
+ },
707
+ )
708
+ .will_respond_with(
709
+ status: 409,
710
+ body: {
711
+ "error" => {
712
+ "code" => 409,
713
+ "message" => Pact.term(generate: "Conflict", matcher:/\S+/),
714
+ "fields" => {
715
+ "previous_version" => Pact.each_like("does not match", :min => 1),
716
+ },
717
+ },
718
+ },
719
+ headers: {
720
+ "Content-Type" => "application/json; charset=utf-8"
721
+ }
722
+ )
723
+ end
724
+
725
+ it "responds with 409 Conflict" do
726
+ error = assert_raises GdsApi::HTTPClientError do
727
+ @api_client.unpublish(@content_id, type: "gone", previous_version: 2)
728
+ end
729
+ assert_equal 409, error.code
730
+ assert_equal "Conflict", error.error_details["error"]["message"]
731
+ end
732
+ end
733
+ end
734
+ end
735
+
545
736
  describe "#get_links" do
546
737
  describe "when there's a links entry with links" do
547
738
  before do
@@ -768,7 +959,7 @@ describe GdsApi::PublishingApiV2 do
768
959
  end
769
960
 
770
961
  describe "optimistic locking" do
771
- describe "if the linkset has not change since it was requested" do
962
+ describe "if the linkset has not changed since it was requested" do
772
963
  before do
773
964
  publishing_api
774
965
  .given("the linkset for #{@content_id} is at version 3")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 30.3.0
4
+ version: 30.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek