notifications-ruby-client 5.2.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Dockerfile CHANGED
@@ -11,3 +11,6 @@ RUN \
11
11
  gnupg
12
12
 
13
13
  WORKDIR /var/project
14
+
15
+ COPY . .
16
+ RUN make bootstrap
data/Makefile CHANGED
@@ -1,22 +1,16 @@
1
1
  .DEFAULT_GOAL := help
2
2
  SHELL := /bin/bash
3
3
 
4
- DOCKER_BUILDER_IMAGE_NAME = govuk/notify-ruby-client-builder
5
-
6
- BUILD_TAG ?= notifications-ruby-client-manual
7
-
8
- DOCKER_CONTAINER_PREFIX = ${USER}-${BUILD_TAG}
9
-
10
4
  .PHONY: help
11
5
  help:
12
6
  @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
13
7
 
14
- .PHONY: dependencies
15
- dependencies: ## Install build dependencies
16
- bundle install --path=vendor/bundle --binstubs=vendor/bin
8
+ .PHONY: bootstrap
9
+ bootstrap: ## Install build dependencies
10
+ bundle install
17
11
 
18
12
  .PHONY: build
19
- build: dependencies ## Build project
13
+ build: bootstrap ## Build project (dummy task for CI)
20
14
 
21
15
  .PHONY: test
22
16
  test: ## Run tests
@@ -26,40 +20,17 @@ test: ## Run tests
26
20
  integration-test: ## Run integration tests
27
21
  bundle exec bin/test_client.rb
28
22
 
29
- .PHONY: generate-env-file
30
- generate-env-file: ## Generate the environment file for running the tests inside a Docker container
31
- bin/generate_docker_env.sh
32
-
33
- .PHONY: prepare-docker-runner-image
34
- prepare-docker-runner-image: ## Prepare the Docker builder image
35
- docker pull `grep "FROM " Dockerfile | cut -d ' ' -f 2` || true
36
- docker build -t ${DOCKER_BUILDER_IMAGE_NAME} .
37
-
38
- .PHONY: build-with-docker
39
- build-with-docker: prepare-docker-runner-image ## Build inside a Docker container
40
- docker run -i --rm \
41
- --name "${DOCKER_CONTAINER_PREFIX}-build" \
42
- -v "`pwd`:/var/project" \
43
- ${DOCKER_BUILDER_IMAGE_NAME} \
44
- make build
23
+ .PHONY: bootstrap-with-docker
24
+ bootstrap-with-docker: ## Prepare the Docker builder image
25
+ docker build -t notifications-ruby-client .
45
26
 
46
27
  .PHONY: test-with-docker
47
- test-with-docker: prepare-docker-runner-image generate-env-file ## Run tests inside a Docker container
48
- docker run -i --rm \
49
- --name "${DOCKER_CONTAINER_PREFIX}-test" \
50
- -v "`pwd`:/var/project" \
51
- --env-file docker.env \
52
- ${DOCKER_BUILDER_IMAGE_NAME} \
53
- make build test
28
+ test-with-docker: ## Run tests inside a Docker container
29
+ ./scripts/run_with_docker.sh make test
54
30
 
55
31
  .PHONY: integration-test-with-docker
56
- integration-test-with-docker: prepare-docker-runner-image generate-env-file ## Run integration tests inside a Docker container
57
- docker run -i --rm \
58
- --name "${DOCKER_CONTAINER_PREFIX}-integration-test" \
59
- -v "`pwd`:/var/project" \
60
- --env-file docker.env \
61
- ${DOCKER_BUILDER_IMAGE_NAME} \
62
- make build integration-test
32
+ integration-test-with-docker: ## Run integration tests inside a Docker container
33
+ ./scripts/run_with_docker.sh make integration-test
63
34
 
64
35
  .PHONY: get-client-version
65
36
  get-client-version: ## Retrieve client version number from source code
@@ -71,9 +42,5 @@ publish-to-rubygems: ## Create gemspec file and publish to rubygems
71
42
  gem build notifications-ruby-client.gemspec --output=release.gem
72
43
  gem push release.gem
73
44
 
74
- .PHONY: clean-docker-containers
75
- clean-docker-containers: ## Clean up any remaining docker containers
76
- docker rm -f $(shell docker ps -q -f "name=${DOCKER_CONTAINER_PREFIX}") 2> /dev/null || true
77
-
78
45
  clean:
79
46
  rm -rf vendor
data/bin/test_client.rb CHANGED
@@ -3,7 +3,9 @@ require './lib/notifications/client'
3
3
 
4
4
  def main
5
5
  client = Notifications::Client.new(ENV['API_KEY'], ENV['NOTIFY_API_URL'])
6
- test_get_template_by_id(client, ENV['EMAIL_TEMPLATE_ID'])
6
+ test_get_email_template_by_id(client, ENV['EMAIL_TEMPLATE_ID'])
7
+ test_get_sms_template_by_id(client, ENV['SMS_TEMPLATE_ID'])
8
+ test_get_letter_template_by_id(client, ENV['LETTER_TEMPLATE_ID'])
7
9
  test_get_template_version(client, ENV['SMS_TEMPLATE_ID'], 1)
8
10
  test_get_all_templates(client)
9
11
  test_get_all_templates_filter_by_type(client)
@@ -25,14 +27,24 @@ def main
25
27
  exit 0
26
28
  end
27
29
 
28
- def test_get_template_by_id(client, id)
30
+ def test_get_email_template_by_id(client, id)
29
31
  response = client.get_template_by_id(id)
30
- test_template_response(response, 'test_get_template_by_id')
32
+ test_template_response(response, 'email', 'test_get_email_template_by_id')
33
+ end
34
+
35
+ def test_get_sms_template_by_id(client, id)
36
+ response = client.get_template_by_id(id)
37
+ test_template_response(response, 'sms', 'test_get_sms_template_by_id')
38
+ end
39
+
40
+ def test_get_letter_template_by_id(client, id)
41
+ response = client.get_template_by_id(id)
42
+ test_template_response(response, 'letter', 'test_get_letter_template_by_id')
31
43
  end
32
44
 
33
45
  def test_get_template_version(client, id, version)
34
46
  response = client.get_template_version(id, version)
35
- test_template_response(response, 'test_get_template_version')
47
+ test_template_response(response, 'sms', 'test_get_template_version')
36
48
  end
37
49
 
38
50
  def test_get_all_templates(client)
@@ -45,9 +57,9 @@ def test_get_all_templates(client)
45
57
  p 'failed test_get_all_templates, expected at least 3 templates returned.'
46
58
  exit 1
47
59
  end
48
- test_template_response(response.collection[0], 'test_get_all_templates')
49
- test_template_response(response.collection[1], 'test_get_all_templates')
50
- test_template_response(response.collection[2], 'test_get_all_templates')
60
+ test_template_response(response.collection[0], 'letter', 'test_get_all_templates')
61
+ test_template_response(response.collection[1], 'email', 'test_get_all_templates')
62
+ test_template_response(response.collection[2], 'sms', 'test_get_all_templates')
51
63
  end
52
64
 
53
65
  def test_get_all_templates_filter_by_type(client)
@@ -60,7 +72,7 @@ def test_get_all_templates_filter_by_type(client)
60
72
  p 'failed test_get_all_templates, expected at least 2 templates returned.'
61
73
  exit 1
62
74
  end
63
- test_template_response(response.collection[0], 'test_get_all_templates')
75
+ test_template_response(response.collection[0], 'sms', 'test_get_all_templates')
64
76
  end
65
77
 
66
78
  def test_generate_template_preview(client, id)
@@ -68,7 +80,7 @@ def test_generate_template_preview(client, id)
68
80
  test_template_preview(response)
69
81
  end
70
82
 
71
- def test_template_response(response, test_method)
83
+ def test_template_response(response, template_type, test_method)
72
84
  unless response.is_a?(Notifications::Client::Template)
73
85
  p 'failed test_get_template_by_id response is not a Notifications::Client::Template'
74
86
  exit 1
@@ -77,7 +89,17 @@ def test_template_response(response, test_method)
77
89
  p 'failed template id is not a String'
78
90
  exit 1
79
91
  end
80
- field_should_not_be_nil(expected_fields_in_template_response, response, test_method)
92
+
93
+ field_should_not_be_nil(
94
+ expected_fields_in_template_response(template_type),
95
+ response,
96
+ test_method
97
+ )
98
+ field_should_be_nil(
99
+ expected_nil_fields_in_template_response(template_type),
100
+ response,
101
+ test_method
102
+ )
81
103
  end
82
104
 
83
105
  def test_template_preview(response)
@@ -255,14 +277,21 @@ def field_should_be_nil(fields, obj, method_name)
255
277
  end
256
278
  end
257
279
 
258
- def expected_fields_in_template_response
259
- %w(id
260
- name
261
- type
262
- created_at
263
- created_by
264
- body
265
- version)
280
+ def expected_fields_in_template_response(template_type)
281
+ {
282
+ "email" => ["id", "name", "type", "created_at", "created_by", "version", "body", "subject"],
283
+ "sms" => ["id", "name", "type", "created_at", "created_by", "version", "body"],
284
+ "letter" => ["id", "name", "type", "created_at", "created_by", "version", "body", "subject",
285
+ "letter_contact_block"],
286
+ }[template_type]
287
+ end
288
+
289
+ def expected_nil_fields_in_template_response(template_type)
290
+ {
291
+ "email" => ["letter_contact_block"],
292
+ "sms" => ["subject", "letter_contact_block"],
293
+ "letter" => [],
294
+ }[template_type]
266
295
  end
267
296
 
268
297
  def expected_fields_in_template_preview
@@ -1,9 +1,14 @@
1
1
  require "base64"
2
2
 
3
3
  module Notifications
4
- def self.prepare_upload(file, is_csv=false)
4
+ def self.prepare_upload(file, is_csv=false, confirm_email_before_download: nil, retention_period: nil)
5
5
  raise ArgumentError.new("File is larger than 2MB") if file.size > Client::MAX_FILE_UPLOAD_SIZE
6
6
 
7
- { file: Base64.strict_encode64(file.read), is_csv: is_csv }
7
+ data = { file: Base64.strict_encode64(file.read), is_csv: is_csv }
8
+
9
+ data[:confirm_email_before_download] = confirm_email_before_download
10
+ data[:retention_period] = retention_period
11
+
12
+ data
8
13
  end
9
14
  end
@@ -13,6 +13,7 @@ module Notifications
13
13
  version
14
14
  body
15
15
  subject
16
+ letter_contact_block
16
17
  ).freeze
17
18
 
18
19
  attr_reader(*FIELDS)
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "5.2.0".freeze
12
+ VERSION = "5.4.0".freeze
13
13
  end
14
14
  end
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake", "~> 13.0"
27
27
  spec.add_development_dependency "rspec", "~> 3.7"
28
28
  spec.add_development_dependency "webmock", "~> 3.4"
29
- spec.add_development_dependency "factory_bot", "~> 5.2"
29
+ spec.add_development_dependency "factory_bot", "~> 6.1"
30
30
  end
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+ DOCKER_IMAGE_NAME=notifications-ruby-client
3
+
4
+ source environment.sh
5
+
6
+ docker run \
7
+ --rm \
8
+ -v "`pwd`:/var/project" \
9
+ -e NOTIFY_API_URL=${NOTIFY_API_URL} \
10
+ -e API_KEY=${API_KEY} \
11
+ -e FUNCTIONAL_TEST_NUMBER=${FUNCTIONAL_TEST_NUMBER} \
12
+ -e FUNCTIONAL_TEST_EMAIL=${FUNCTIONAL_TEST_EMAIL} \
13
+ -e EMAIL_TEMPLATE_ID=${EMAIL_TEMPLATE_ID} \
14
+ -e SMS_TEMPLATE_ID=${SMS_TEMPLATE_ID} \
15
+ -e LETTER_TEMPLATE_ID=${LETTER_TEMPLATE_ID} \
16
+ -e EMAIL_REPLY_TO_ID=${EMAIL_REPLY_TO_ID} \
17
+ -e SMS_SENDER_ID=${SMS_SENDER_ID} \
18
+ -e API_SENDING_KEY=${API_SENDING_KEY} \
19
+ -e INBOUND_SMS_QUERY_KEY=${INBOUND_SMS_QUERY_KEY} \
20
+ -it \
21
+ ${DOCKER_IMAGE_NAME} \
22
+ ${@}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-04 00:00:00.000000000 Z
11
+ date: 2022-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '5.2'
95
+ version: '6.1'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '5.2'
102
+ version: '6.1'
103
103
  description:
104
104
  email:
105
105
  - notify@digital.cabinet-office.gov.uk
@@ -107,6 +107,7 @@ executables: []
107
107
  extensions: []
108
108
  extra_rdoc_files: []
109
109
  files:
110
+ - ".dockerignore"
110
111
  - ".github/PULL_REQUEST_TEMPLATE.md"
111
112
  - ".gitignore"
112
113
  - ".rspec"
@@ -121,7 +122,6 @@ files:
121
122
  - README.md
122
123
  - Rakefile
123
124
  - bin/console
124
- - bin/generate_docker_env.sh
125
125
  - bin/setup
126
126
  - bin/test_client.rb
127
127
  - lib/notifications/client.rb
@@ -140,6 +140,7 @@ files:
140
140
  - lib/notifications/client/uuid_validator.rb
141
141
  - lib/notifications/client/version.rb
142
142
  - notifications-ruby-client.gemspec
143
+ - scripts/run_with_docker.sh
143
144
  homepage: https://github.com/alphagov/notifications-ruby-client
144
145
  licenses: []
145
146
  metadata: {}
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  - !ruby/object:Gem::Version
159
160
  version: '0'
160
161
  requirements: []
161
- rubygems_version: 3.0.3
162
+ rubygems_version: 3.0.3.1
162
163
  signing_key:
163
164
  specification_version: 4
164
165
  summary: Ruby client for GOV.UK Notifications API
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -eo pipefail
4
-
5
- function exit_with_msg {
6
- echo $1
7
- exit $2
8
- }
9
-
10
- echo -n "" > docker.env
11
-
12
- env_vars=(
13
- NOTIFY_API_URL
14
- SERVICE_ID
15
- API_KEY
16
- FUNCTIONAL_TEST_EMAIL
17
- FUNCTIONAL_TEST_NUMBER
18
- EMAIL_TEMPLATE_ID
19
- SMS_TEMPLATE_ID
20
- LETTER_TEMPLATE_ID
21
- EMAIL_REPLY_TO_ID
22
- SMS_SENDER_ID
23
- API_SENDING_KEY
24
- INBOUND_SMS_QUERY_KEY
25
- )
26
-
27
- for env_var in "${env_vars[@]}"; do
28
- echo "${env_var}=${!env_var}" >> docker.env
29
- done