From a60bc8d12190237649bc577966b8f4b8b94d82a9 Mon Sep 17 00:00:00 2001 From: Tiago Freire Date: Thu, 18 Aug 2016 19:09:45 -0300 Subject: Add tests to uptade Record --- .../powerdnsex/managers/records_manager_test.exs | 32 ++++++++++++++++++++++ .../records_manager/update/invalid_record.json | 31 +++++++++++++++++++++ .../records_manager/update/not_found.json | 31 +++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 test/support/cassettes/records_manager/update/invalid_record.json create mode 100644 test/support/cassettes/records_manager/update/not_found.json (limited to 'test') diff --git a/test/lib/powerdnsex/managers/records_manager_test.exs b/test/lib/powerdnsex/managers/records_manager_test.exs index 3b91fc2..5f314bd 100644 --- a/test/lib/powerdnsex/managers/records_manager_test.exs +++ b/test/lib/powerdnsex/managers/records_manager_test.exs @@ -25,6 +25,18 @@ defmodule PowerDNSex.RecordsManagerTest do records: [{"127.0.0.1", true}] } + @invalid_record %{ + name: "updated-record.my-domain.art.", + type: "NS", + ttl: 86800, + records: [{"127.0.0.1", true}] + } + + @invalid_zone %Zone{ + name: "not-canonical-domain.tst", + url: "api/v1/servers/localhost/zones/not-canonical-domain.tst" + } + setup do # Config.set_url # Config.set_token @@ -64,10 +76,30 @@ defmodule PowerDNSex.RecordsManagerTest do end end + @tag :records_manager_update test "the return given correct params" do use_cassette "records_manager/update/success" do assert RecordsManager.update(@valid_zone, @updated_record) == :ok end end + + @tag :records_manager_update + test "the return given incorrect zone" do + use_cassette "records_manager/update/not_found" do + response = RecordsManager.update(@invalid_zone, @updated_record) + error_msg = "Could not find domain '#{@invalid_zone.name}.'" + assert response.error == error_msg + end + end + + @tag :records_manager_update + test "the return given incorrect params" do + use_cassette "records_manager/update/invalid_record" do + response = RecordsManager.update(@valid_zone, @invalid_record) + error_msg = "Record updated-record.my-domain.art./NS '127.0.0.1': " <> + "Not in expected format (parsed as '127.0.0.1.')" + assert response.error == error_msg + end + end end end diff --git a/test/support/cassettes/records_manager/update/invalid_record.json b/test/support/cassettes/records_manager/update/invalid_record.json new file mode 100644 index 0000000..df6d73a --- /dev/null +++ b/test/support/cassettes/records_manager/update/invalid_record.json @@ -0,0 +1,31 @@ +[ + { + "request": { + "body": "{\"rrsets\":[{\"type\":\"NS\",\"ttl\":86800,\"records\":[{\"disabled\":true,\"content\":\"127.0.0.1\"}],\"name\":\"updated-record.my-domain.art.\",\"changetype\":\"REPLACE\"}]}", + "headers": { + "X-API-Key": "Locaweb2016" + }, + "method": "patch", + "options": [], + "request_body": "", + "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/my-domain.art." + }, + "response": { + "body": "{\"error\": \"Record updated-record.my-domain.art./NS '127.0.0.1': Not in expected format (parsed as '127.0.0.1.')\"}", + "headers": { + "Access-Control-Allow-Origin": "*", + "Connection": "close", + "Content-Length": "113", + "Content-Security-Policy": "default-src 'self'; style-src 'self' 'unsafe-inline'", + "Content-Type": "application/json", + "Server": "PowerDNS/4.0.1", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-Permitted-Cross-Domain-Policies": "none", + "X-Xss-Protection": "1; mode=block" + }, + "status_code": 422, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/test/support/cassettes/records_manager/update/not_found.json b/test/support/cassettes/records_manager/update/not_found.json new file mode 100644 index 0000000..38edad2 --- /dev/null +++ b/test/support/cassettes/records_manager/update/not_found.json @@ -0,0 +1,31 @@ +[ + { + "request": { + "body": "{\"rrsets\":[{\"type\":\"A\",\"ttl\":86800,\"records\":[{\"disabled\":true,\"content\":\"127.0.0.1\"}],\"name\":\"updated-record.my-domain.art.\",\"changetype\":\"REPLACE\"}]}", + "headers": { + "X-API-Key": "Locaweb2016" + }, + "method": "patch", + "options": [], + "request_body": "", + "url": "http://cpro36999.systemintegration.locaweb.com.br/api/v1/servers/localhost/zones/not-canonical-domain.tst" + }, + "response": { + "body": "{\"error\": \"Could not find domain 'not-canonical-domain.tst.'\"}", + "headers": { + "Access-Control-Allow-Origin": "*", + "Connection": "close", + "Content-Length": "62", + "Content-Security-Policy": "default-src 'self'; style-src 'self' 'unsafe-inline'", + "Content-Type": "application/json", + "Server": "PowerDNS/4.0.1", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-Permitted-Cross-Domain-Policies": "none", + "X-Xss-Protection": "1; mode=block" + }, + "status_code": 422, + "type": "ok" + } + } +] \ No newline at end of file -- cgit v1.2.3