A pact between GDS API Adapters and Email Alert API

Requests from GDS API Adapters to Email Alert API

Interactions

Given a content change with content_id 5fc8fb2b-c0b1-4490-99cb-c987a53afb75 exists, upon receiving a conflicting content change from GDS API Adapters, with

{
  "method": "post",
  "path": "/content-changes",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json",
    "Govuk-Request-Id": "request-id-1"
  },
  "body": {
    "content_id": "5fc8fb2b-c0b1-4490-99cb-c987a53afb75",
    "base_path": "government/base_path",
    "public_updated_at": "2022-01-01 00:00:00 +0000"
  }
}

Email Alert API will respond with:

{
  "status": 409,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "error": "Content change already received"
  }
}

Upon receiving a request for a missing subscriber list from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscriber-lists",
  "query": "tags[topics][any][]=motoring%2Froad_rage",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 404,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "error": "Could not find the subscriber list"
  }
}

Given a subscriber list with the tag topic: motoring/road_rage exists, upon receiving a request for the subscriber list from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscriber-lists",
  "query": "tags[topics][any][]=motoring%2Froad_rage",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscriber_list": {
      "id": 1,
      "links": {
      },
      "tags": {
        "topics": {
          "any": [
            "motoring/road_rage"
          ]
        }
      },
      "document_type": "",
      "slug": "title-1",
      "title": "title 1"
    }
  }
}

Given a verified govuk_account_session exists with a matching subscriber, upon receiving a request to authenticate by the govuk_account_session from GDS API Adapters, with

{
  "method": "post",
  "path": "/subscribers/govuk-account",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json"
  },
  "body": {
    "govuk_account_session": "session identifier"
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscriber": {
      "id": 1,
      "address": "test@example.com",
      "created_at": "2022-07-04 13:44:42 +0000",
      "updated_at": "2022-07-04 13:44:42 +0000",
      "govuk_account_id": null
    }
  }
}

Given a govuk_account_session exists but isn't verified, upon receiving a request to authenticate by the govuk_account_session from GDS API Adapters, with

{
  "method": "post",
  "path": "/subscribers/govuk-account",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json"
  },
  "body": {
    "govuk_account_session": "session identifier"
  }
}

Email Alert API will respond with:

{
  "status": 403
}

Upon receiving a request to change a missing subscriber's email address from GDS API Adapters, with

{
  "method": "patch",
  "path": "/subscribers/1",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json"
  },
  "body": {
    "new_address": "test2@example.com"
  }
}

Email Alert API will respond with:

{
  "status": 404
}

Given a subscriber exists, upon receiving a request to change that subscriber's email address from GDS API Adapters, with

{
  "method": "patch",
  "path": "/subscribers/1",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json"
  },
  "body": {
    "new_address": "test2@example.com"
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscriber": {
      "id": 1,
      "address": "test2@example.com",
      "created_at": "2022-07-04 13:44:44 +0000",
      "updated_at": "2022-07-04 13:44:44 +0000",
      "govuk_account_id": null
    }
  }
}

Upon receiving a request to find or create a subscriber list from GDS API Adapters, with

{
  "method": "post",
  "path": "/subscriber-lists",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json"
  },
  "body": {
    "title": "new-title",
    "tags": {
      "topics": {
        "any": [
          "motoring/road_rage"
        ]
      }
    }
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscriber_list": {
      "id": 1,
      "links": {
      },
      "tags": {
        "topics": {
          "any": [
            "motoring/road_rage"
          ]
        }
      },
      "document_type": "",
      "slug": "title-1",
      "title": "new-title"
    }
  }
}

Given a subscriber list with the tag topic: motoring/road_rage exists, upon receiving a request to find or create a subscriber list from GDS API Adapters, with

{
  "method": "post",
  "path": "/subscriber-lists",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json"
  },
  "body": {
    "title": "new-title",
    "tags": {
      "topics": {
        "any": [
          "motoring/road_rage"
        ]
      }
    }
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscriber_list": {
      "id": 1,
      "links": {
      },
      "tags": {
        "topics": {
          "any": [
            "motoring/road_rage"
          ]
        }
      },
      "document_type": "",
      "slug": "title-1",
      "title": "new-title"
    }
  }
}

Upon receiving a valid content change from GDS API Adapters, with

{
  "method": "post",
  "path": "/content-changes",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()",
    "Content-Type": "application/json",
    "Govuk-Request-Id": "request-id-1"
  },
  "body": {
    "content_id": "5fc8fb2b-c0b1-4490-99cb-c987a53afb75",
    "title": "Email Alert API Pact Tests",
    "base_path": "government/base_path",
    "change_note": "change note",
    "public_updated_at": "2022-07-04 13:44:47 +0000",
    "email_document_supertype": "email document supertype",
    "government_document_supertype": "government document supertype",
    "document_type": "document type",
    "publishing_app": "publishing app",
    "description": "description"
  }
}

Email Alert API will respond with:

{
  "status": 202,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "message": "Content change queued for sending"
  }
}

Upon receiving the request to get a missing subscriber list from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscriber-lists/title-1",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 404,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "error": "Could not find the subscriber list"
  }
}

Upon receiving the request to get a missing subscription from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscriptions/719efe7b-00d0-4168-ac30-99fe6093e3fc",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 404
}

Upon receiving the request to get subscriptions for a missing subscriber from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscribers/1/subscriptions",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 404
}

Given a subscription with the uuid 719efe7b-00d0-4168-ac30-99fe6093e3fc exists, upon receiving the request to get subscriptions for that subscriber from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscribers/1/subscriptions",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscriber": {
      "id": 1,
      "address": "test@example.com",
      "created_at": "2022-07-04 13:44:42 +0000",
      "updated_at": "2022-07-04 13:44:42 +0000",
      "govuk_account_id": null
    },
    "subscriptions": [
      {
        "id": "719efe7b-00d0-4168-ac30-99fe6093e3fc",
        "subscriber_list": {
          "id": 1,
          "links": {
          },
          "tags": {
            "topics": {
              "any": [
                "motoring/road_rage"
              ]
            }
          },
          "document_type": "",
          "slug": "title-1",
          "title": "title 1"
        },
        "ended_at": null,
        "ended_reason": null,
        "frequency": "immediately",
        "source": "user_signed_up"
      }
    ]
  }
}

Given a subscriber list with slug title-1 exists, upon receiving the request to get that subscriber list from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscriber-lists/title-1",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscriber_list": {
      "id": 1,
      "links": {
      },
      "tags": {
        "topics": {
          "any": [
            "motoring/road_rage"
          ]
        }
      },
      "document_type": "",
      "slug": "title-1",
      "title": "title 1"
    }
  }
}

Given a subscription with the uuid 719efe7b-00d0-4168-ac30-99fe6093e3fc exists, upon receiving the request to get that subscription from GDS API Adapters, with

{
  "method": "get",
  "path": "/subscriptions/719efe7b-00d0-4168-ac30-99fe6093e3fc",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "subscription": {
      "id": "719efe7b-00d0-4168-ac30-99fe6093e3fc",
      "subscriber_list": {
        "id": 1,
        "links": {
        },
        "tags": {
          "topics": {
            "any": [
              "motoring/road_rage"
            ]
          }
        },
        "document_type": "",
        "slug": "title-1",
        "title": "title 1"
      },
      "subscriber": {
        "id": 1,
        "address": "test@example.com",
        "created_at": "2022-07-04 13:44:47 +0000",
        "updated_at": "2022-07-04 13:44:47 +0000",
        "govuk_account_id": null
      },
      "ended_at": null,
      "ended_reason": null,
      "frequency": "immediately",
      "source": "user_signed_up"
    }
  }
}

Upon receiving the request to unsubscribe a missing uuid from GDS API Adapters, with

{
  "method": "post",
  "path": "/unsubscribe/719efe7b-00d0-4168-ac30-99fe6093e3fc",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 404
}

Given a subscription with the uuid 719efe7b-00d0-4168-ac30-99fe6093e3fc exists, upon receiving the request to unsubscribe that uuid from GDS API Adapters, with

{
  "method": "post",
  "path": "/unsubscribe/719efe7b-00d0-4168-ac30-99fe6093e3fc",
  "headers": {
    "Accept": "application/json",
    "User-Agent": "gds-api-adapters/80.0.1 ()"
  }
}

Email Alert API will respond with:

{
  "status": 204,
  "body": ""
}