diff --git a/lib/braze_ruby/endpoints/delete_users.rb b/lib/braze_ruby/endpoints/delete_users.rb index 1dfeeaa..b15001e 100644 --- a/lib/braze_ruby/endpoints/delete_users.rb +++ b/lib/braze_ruby/endpoints/delete_users.rb @@ -13,6 +13,14 @@ def delete_users(payload) delete_users_action(external_ids: payload.compact.uniq) end + def delete_users_by_alias(payload) + delete_users_action(user_aliases: payload.compact.uniq) + end + + def delete_users_by_braze_id(payload) + delete_users_action(braze_ids: payload.compact.uniq) + end + private def delete_users_service diff --git a/lib/braze_ruby/rest/delete_users.rb b/lib/braze_ruby/rest/delete_users.rb index e15f862..70a352a 100644 --- a/lib/braze_ruby/rest/delete_users.rb +++ b/lib/braze_ruby/rest/delete_users.rb @@ -3,9 +3,11 @@ module BrazeRuby module REST class DeleteUsers < Base - def perform(external_ids: []) + def perform(external_ids: [], user_aliases: [], braze_ids: []) http.post "/users/delete", { - external_ids: external_ids + external_ids: external_ids, + user_aliases: user_aliases, + braze_ids: braze_ids, } end end diff --git a/spec/braze_ruby/endpoints/delete_users_spec.rb b/spec/braze_ruby/endpoints/delete_users_spec.rb index 0290123..f89944d 100644 --- a/spec/braze_ruby/endpoints/delete_users_spec.rb +++ b/spec/braze_ruby/endpoints/delete_users_spec.rb @@ -28,4 +28,30 @@ def api_key delete_users! end end + + describe "#delete_users_by_alias" do + let(:payload) { [1, 2, 3] } + + subject(:delete_users_by_alias!) { api.delete_users_by_alias(payload) } + + it "deletes users by alias" do + expect(delete_users_service).to receive(:perform) + .with(user_aliases: payload) + + delete_users_by_alias! + end + end + + describe "#delete_users_by_braze_id" do + let(:payload) { [1, 2, 3] } + + subject(:delete_users_by_braze_id!) { api.delete_users_by_braze_id(payload) } + + it "deletes users by braze id" do + expect(delete_users_service).to receive(:perform) + .with(braze_ids: payload) + + delete_users_by_braze_id! + end + end end diff --git a/spec/braze_ruby/rest/delete_users_spec.rb b/spec/braze_ruby/rest/delete_users_spec.rb index 7e04139..5e8c5f8 100644 --- a/spec/braze_ruby/rest/delete_users_spec.rb +++ b/spec/braze_ruby/rest/delete_users_spec.rb @@ -5,7 +5,13 @@ describe BrazeRuby::REST::DeleteUsers do let(:http) { double(:http) } - let(:payload) { {external_ids: [1, 2, 3]} } + let(:payload) do + { + external_ids: [1, 2, 3], + user_aliases: [4, 5, 6], + braze_ids: [7, 8, 9], + } + end subject { described_class.new :api_key, :rest_url, {} } diff --git a/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml b/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml index 201c0bf..92a450b 100644 --- a/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml +++ b/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml @@ -5,7 +5,7 @@ http_interactions: uri: "/users/delete" body: encoding: UTF-8 - string: '{"external_ids":[400,401,402]}' + string: '{"external_ids":[400,401,402],"user_aliases":[],"braze_ids":[]}' headers: Content-Type: - application/json diff --git a/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml b/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml index 1920156..961ce6a 100644 --- a/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml +++ b/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml @@ -5,7 +5,7 @@ http_interactions: uri: "/users/delete" body: encoding: UTF-8 - string: '{"external_ids":[400,401,402]}' + string: '{"external_ids":[400,401,402],"user_aliases":[],"braze_ids":[]}' headers: Content-Type: - application/json diff --git a/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml b/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml index f67b78d..303935a 100644 --- a/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml +++ b/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml @@ -5,7 +5,7 @@ http_interactions: uri: "/users/delete" body: encoding: UTF-8 - string: '{"external_ids":[400,401,402]}' + string: '{"external_ids":[400,401,402],"user_aliases":[],"braze_ids":[]}' headers: Content-Type: - application/json diff --git a/spec/fixtures/responses/delete_users_by_alias/unauthorized/responds_with_unauthorized.yml b/spec/fixtures/responses/delete_users_by_alias/unauthorized/responds_with_unauthorized.yml new file mode 100644 index 0000000..07b5e8a --- /dev/null +++ b/spec/fixtures/responses/delete_users_by_alias/unauthorized/responds_with_unauthorized.yml @@ -0,0 +1,67 @@ +--- +http_interactions: +- request: + method: post + uri: "/users/delete" + body: + encoding: UTF-8 + string: '{"external_ids":[],"user_aliases":["alias1","alias2","alias3"],"braze_ids":[]}' + headers: + Content-Type: + - application/json + Accept: + - application/json + User-Agent: + - Braze Ruby gem v0.8.0 + Authorization: + - Bearer non-existent + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 401 + message: Unauthorized + headers: + Connection: + - keep-alive + Content-Type: + - application/json + Server: + - nginx + X-Ratelimit-Limit: + - '' + X-Ratelimit-Remaining: + - '' + X-Ratelimit-Reset: + - '' + Cache-Control: + - no-cache + X-Request-Id: + - be73e5ce-a55d-4847-9097-eee433855120 + X-Runtime: + - '0.001345' + Accept-Ranges: + - bytes + Date: + - Thu, 12 Jan 2023 19:19:06 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-sjc10052-SJC + X-Cache: + - MISS + X-Cache-Hits: + - '0' + X-Timer: + - S1673551147.709402,VS0,VE78 + Vary: + - Origin,Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: '{"message":"Invalid API key: non-existent"}' + recorded_at: Thu, 12 Jan 2023 19:19:06 GMT +recorded_with: VCR 6.1.0 diff --git a/spec/fixtures/responses/delete_users_by_alias/with_success/responds_with_created.yml b/spec/fixtures/responses/delete_users_by_alias/with_success/responds_with_created.yml new file mode 100644 index 0000000..5b97f6f --- /dev/null +++ b/spec/fixtures/responses/delete_users_by_alias/with_success/responds_with_created.yml @@ -0,0 +1,71 @@ +--- +http_interactions: + - request: + method: post + uri: "/users/delete" + body: + encoding: UTF-8 + string: '{"external_ids":[],"user_aliases":["alias1","alias2","alias3"],"braze_ids":[]}' + headers: + Content-Type: + - application/json + Accept: + - application/json + User-Agent: + - Braze Ruby gem v0.3.3 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: Created + headers: + Connection: + - keep-alive + Content-Length: + - '58' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/json + Etag: + - W/"9a22d0f53e9efcbef8e52c6a21060bc1" + Server: + - nginx + Strict-Transport-Security: + - max-age=0; includeSubDomains + - max-age=31536000; includeSubDomains + X-Ratelimit-Limit: + - '250000' + X-Ratelimit-Remaining: + - '249937' + X-Ratelimit-Reset: + - '1592427600' + X-Request-Id: + - dd8e1db7-bb0d-4e71-a14a-c4c5c9322f49 + X-Runtime: + - '0.005861' + Accept-Ranges: + - bytes + Date: + - Wed, 17 Jun 2020 20:59:32 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-hhn4035-HHN + X-Cache: + - MISS + X-Cache-Hits: + - '0' + X-Timer: + - S1592427572.293833,VS0,VE9 + Vary: + - Origin,Accept-Encoding + body: + encoding: ASCII-8BIT + string: '{"deleted":3,"message":"success"}' + http_version: + recorded_at: Wed, 17 Jun 2020 20:59:32 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/responses/delete_users_by_alias/with_success/responds_with_success_message.yml b/spec/fixtures/responses/delete_users_by_alias/with_success/responds_with_success_message.yml new file mode 100644 index 0000000..6dfd0eb --- /dev/null +++ b/spec/fixtures/responses/delete_users_by_alias/with_success/responds_with_success_message.yml @@ -0,0 +1,71 @@ +--- +http_interactions: + - request: + method: post + uri: "/users/delete" + body: + encoding: UTF-8 + string: '{"external_ids":[],"user_aliases":["alias1","alias2","alias3"],"braze_ids":[]}' + headers: + Content-Type: + - application/json + Accept: + - application/json + User-Agent: + - Braze Ruby gem v0.3.3 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: Created + headers: + Connection: + - keep-alive + Content-Length: + - '58' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/json + Etag: + - W/"9a22d0f53e9efcbef8e52c6a21060bc1" + Server: + - nginx + Strict-Transport-Security: + - max-age=0; includeSubDomains + - max-age=31536000; includeSubDomains + X-Ratelimit-Limit: + - '250000' + X-Ratelimit-Remaining: + - '249936' + X-Ratelimit-Reset: + - '1592427600' + X-Request-Id: + - '096a3b98-e784-4eb4-ba32-dd18749c3ceb' + X-Runtime: + - '0.006707' + Accept-Ranges: + - bytes + Date: + - Wed, 17 Jun 2020 20:59:32 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-hhn4059-HHN + X-Cache: + - MISS + X-Cache-Hits: + - '0' + X-Timer: + - S1592427572.403094,VS0,VE9 + Vary: + - Origin,Accept-Encoding + body: + encoding: ASCII-8BIT + string: '{"deleted":3,"message":"success"}' + http_version: + recorded_at: Wed, 17 Jun 2020 20:59:32 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/responses/delete_users_by_braze_id/unauthorized/responds_with_unauthorized.yml b/spec/fixtures/responses/delete_users_by_braze_id/unauthorized/responds_with_unauthorized.yml new file mode 100644 index 0000000..0e87964 --- /dev/null +++ b/spec/fixtures/responses/delete_users_by_braze_id/unauthorized/responds_with_unauthorized.yml @@ -0,0 +1,67 @@ +--- +http_interactions: +- request: + method: post + uri: "/users/delete" + body: + encoding: UTF-8 + string: '{"external_ids":[],"user_aliases":[],"braze_ids":["id1","id2","id3"]}' + headers: + Content-Type: + - application/json + Accept: + - application/json + User-Agent: + - Braze Ruby gem v0.8.0 + Authorization: + - Bearer non-existent + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 401 + message: Unauthorized + headers: + Connection: + - keep-alive + Content-Type: + - application/json + Server: + - nginx + X-Ratelimit-Limit: + - '' + X-Ratelimit-Remaining: + - '' + X-Ratelimit-Reset: + - '' + Cache-Control: + - no-cache + X-Request-Id: + - a9eda6a8-75eb-4f7e-abbb-a654bbf48783 + X-Runtime: + - '0.001064' + Accept-Ranges: + - bytes + Date: + - Thu, 12 Jan 2023 19:19:07 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-sjc10034-SJC + X-Cache: + - MISS + X-Cache-Hits: + - '0' + X-Timer: + - S1673551148.691738,VS0,VE78 + Vary: + - Origin,Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: '{"message":"Invalid API key: non-existent"}' + recorded_at: Thu, 12 Jan 2023 19:19:07 GMT +recorded_with: VCR 6.1.0 diff --git a/spec/fixtures/responses/delete_users_by_braze_id/with_success/responds_with_created.yml b/spec/fixtures/responses/delete_users_by_braze_id/with_success/responds_with_created.yml new file mode 100644 index 0000000..ceb3583 --- /dev/null +++ b/spec/fixtures/responses/delete_users_by_braze_id/with_success/responds_with_created.yml @@ -0,0 +1,71 @@ +--- +http_interactions: + - request: + method: post + uri: "/users/delete" + body: + encoding: UTF-8 + string: '{"external_ids":[],"user_aliases":[],"braze_ids":["id1","id2","id3"]}' + headers: + Content-Type: + - application/json + Accept: + - application/json + User-Agent: + - Braze Ruby gem v0.3.3 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: Created + headers: + Connection: + - keep-alive + Content-Length: + - '58' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/json + Etag: + - W/"9a22d0f53e9efcbef8e52c6a21060bc1" + Server: + - nginx + Strict-Transport-Security: + - max-age=0; includeSubDomains + - max-age=31536000; includeSubDomains + X-Ratelimit-Limit: + - '250000' + X-Ratelimit-Remaining: + - '249937' + X-Ratelimit-Reset: + - '1592427600' + X-Request-Id: + - dd8e1db7-bb0d-4e71-a14a-c4c5c9322f49 + X-Runtime: + - '0.005861' + Accept-Ranges: + - bytes + Date: + - Wed, 17 Jun 2020 20:59:32 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-hhn4035-HHN + X-Cache: + - MISS + X-Cache-Hits: + - '0' + X-Timer: + - S1592427572.293833,VS0,VE9 + Vary: + - Origin,Accept-Encoding + body: + encoding: ASCII-8BIT + string: '{"deleted":3,"message":"success"}' + http_version: + recorded_at: Wed, 17 Jun 2020 20:59:32 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/responses/delete_users_by_braze_id/with_success/responds_with_success_message.yml b/spec/fixtures/responses/delete_users_by_braze_id/with_success/responds_with_success_message.yml new file mode 100644 index 0000000..24cc772 --- /dev/null +++ b/spec/fixtures/responses/delete_users_by_braze_id/with_success/responds_with_success_message.yml @@ -0,0 +1,71 @@ +--- +http_interactions: + - request: + method: post + uri: "/users/delete" + body: + encoding: UTF-8 + string: '{"external_ids":[],"user_aliases":[],"braze_ids":["id1","id2","id3"]}' + headers: + Content-Type: + - application/json + Accept: + - application/json + User-Agent: + - Braze Ruby gem v0.3.3 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: Created + headers: + Connection: + - keep-alive + Content-Length: + - '58' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/json + Etag: + - W/"9a22d0f53e9efcbef8e52c6a21060bc1" + Server: + - nginx + Strict-Transport-Security: + - max-age=0; includeSubDomains + - max-age=31536000; includeSubDomains + X-Ratelimit-Limit: + - '250000' + X-Ratelimit-Remaining: + - '249936' + X-Ratelimit-Reset: + - '1592427600' + X-Request-Id: + - '096a3b98-e784-4eb4-ba32-dd18749c3ceb' + X-Runtime: + - '0.006707' + Accept-Ranges: + - bytes + Date: + - Wed, 17 Jun 2020 20:59:32 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-hhn4059-HHN + X-Cache: + - MISS + X-Cache-Hits: + - '0' + X-Timer: + - S1592427572.403094,VS0,VE9 + Vary: + - Origin,Accept-Encoding + body: + encoding: ASCII-8BIT + string: '{"deleted":3,"message":"success"}' + http_version: + recorded_at: Wed, 17 Jun 2020 20:59:32 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/integrations/delete_users_spec.rb b/spec/integrations/delete_users_spec.rb index 25b984b..7e687d2 100644 --- a/spec/integrations/delete_users_spec.rb +++ b/spec/integrations/delete_users_spec.rb @@ -30,3 +30,61 @@ end end end + +describe "delete users by alias" do + let(:user_aliases) { ["alias1", "alias2", "alias3"] } + + subject(:delete_users_by_alias) do + api.delete_users_by_alias(user_aliases) + end + + context "with success", vcr: true do + it "responds with created" do + expect(delete_users_by_alias.status).to be 201 + end + + it "responds with success message" do + expect(JSON.parse(delete_users_by_alias.body)).to include( + "deleted" => 3, + "message" => "success" + ) + end + end + + context "unauthorized", vcr: true do + let(:api_key) { "non-existent" } + + it "responds with unauthorized" do + expect(delete_users_by_alias.status).to be 401 + end + end +end + +describe "delete users by braze id" do + let(:braze_ids) { ["id1", "id2", "id3"] } + + subject(:delete_users_by_braze_id) do + api.delete_users_by_braze_id(braze_ids) + end + + context "with success", vcr: true do + it "responds with created" do + expect(delete_users_by_braze_id.status).to be 201 + end + + it "responds with success message" do + expect(JSON.parse(delete_users_by_braze_id.body)).to include( + "deleted" => 3, + "message" => "success" + ) + end + end + + context "unauthorized", vcr: true do + let(:api_key) { "non-existent" } + + it "responds with unauthorized" do + expect(delete_users_by_braze_id.status).to be 401 + end + end +end