From 6cac61e31356645710980fe1099a234cea1db114 Mon Sep 17 00:00:00 2001 From: Tom Milewski Date: Mon, 16 Dec 2024 17:10:42 -0500 Subject: [PATCH] chore: Remove outdated tests --- test/fixtures/all_allowlist_identifiers.json | 9 -- test/fixtures/all_clients.json | 14 -- test/fixtures/all_sessions.json | 12 -- test/fixtures/all_users.json | 88 ----------- test/fixtures/allowlist_identifier_1.json | 7 - .../allowlist_identifier_1_deleted.json | 5 - test/fixtures/allowlist_toggle.json | 5 - test/fixtures/client_1.json | 12 -- test/fixtures/email_address_1.json | 7 - test/fixtures/email_address_1_deleted.json | 5 - test/fixtures/email_address_1_updated.json | 13 -- test/fixtures/email_created.json | 10 -- test/fixtures/jwks.json | 1 - test/fixtures/jwt_valid.json | 1 - test/fixtures/phone_number_1.json | 10 -- test/fixtures/phone_number_1_deleted.json | 5 - test/fixtures/phone_number_1_updated.json | 16 -- test/fixtures/session_1.json | 10 -- test/fixtures/testing_token_1.json | 5 - test/fixtures/user_1.json | 48 ------ test/fixtures/user_1_deleted.json | 5 - test/fixtures/user_1_updated.json | 48 ------ test/fixtures/users_oauth_access_token.json | 8 - test/resources/allowlist_identifiers_test.rb | 29 ---- test/resources/allowlist_test.rb | 20 --- test/resources/clients_test.rb | 34 ----- test/resources/email_addresses_test.rb | 53 ------- test/resources/emails_test.rb | 25 ---- test/resources/phone_numbers_test.rb | 53 ------- test/resources/sessions_test.rb | 41 ------ test/resources/testing_tokens_test.rb | 25 ---- test/resources/users_test.rb | 63 -------- test/sdk_test.rb | 137 ------------------ test/test_helper.rb | 25 ---- 34 files changed, 849 deletions(-) delete mode 100644 test/fixtures/all_allowlist_identifiers.json delete mode 100644 test/fixtures/all_clients.json delete mode 100644 test/fixtures/all_sessions.json delete mode 100644 test/fixtures/all_users.json delete mode 100644 test/fixtures/allowlist_identifier_1.json delete mode 100644 test/fixtures/allowlist_identifier_1_deleted.json delete mode 100644 test/fixtures/allowlist_toggle.json delete mode 100644 test/fixtures/client_1.json delete mode 100644 test/fixtures/email_address_1.json delete mode 100644 test/fixtures/email_address_1_deleted.json delete mode 100644 test/fixtures/email_address_1_updated.json delete mode 100644 test/fixtures/email_created.json delete mode 100644 test/fixtures/jwks.json delete mode 100644 test/fixtures/jwt_valid.json delete mode 100644 test/fixtures/phone_number_1.json delete mode 100644 test/fixtures/phone_number_1_deleted.json delete mode 100644 test/fixtures/phone_number_1_updated.json delete mode 100644 test/fixtures/session_1.json delete mode 100644 test/fixtures/testing_token_1.json delete mode 100644 test/fixtures/user_1.json delete mode 100644 test/fixtures/user_1_deleted.json delete mode 100644 test/fixtures/user_1_updated.json delete mode 100644 test/fixtures/users_oauth_access_token.json delete mode 100644 test/resources/allowlist_identifiers_test.rb delete mode 100644 test/resources/allowlist_test.rb delete mode 100644 test/resources/clients_test.rb delete mode 100644 test/resources/email_addresses_test.rb delete mode 100644 test/resources/emails_test.rb delete mode 100644 test/resources/phone_numbers_test.rb delete mode 100644 test/resources/sessions_test.rb delete mode 100644 test/resources/testing_tokens_test.rb delete mode 100644 test/resources/users_test.rb delete mode 100644 test/sdk_test.rb delete mode 100644 test/test_helper.rb diff --git a/test/fixtures/all_allowlist_identifiers.json b/test/fixtures/all_allowlist_identifiers.json deleted file mode 100644 index 24f1e12..0000000 --- a/test/fixtures/all_allowlist_identifiers.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "object": "allowlist_identifier", - "id": "alid_1", - "identifier": "+1655559004", - "created_at": 1620370000, - "updated_at": 1620370000 - } -] diff --git a/test/fixtures/all_clients.json b/test/fixtures/all_clients.json deleted file mode 100644 index 2c1b919..0000000 --- a/test/fixtures/all_clients.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "object": "client", - "id": "client_1", - "session_ids": [ - "sess_1q8u7QQhKOGRitdFGreHB00443j" - ], - "sign_in_attempt_id": null, - "sign_up_attempt_id": null, - "last_active_session_id": "sess_1q8u7QQhKOGRitdFGreHB00443j", - "created_at": 1616473358, - "updated_at": 1616473358 - } -] diff --git a/test/fixtures/all_sessions.json b/test/fixtures/all_sessions.json deleted file mode 100644 index 8a100b0..0000000 --- a/test/fixtures/all_sessions.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "object": "session", - "id": "sess_1", - "client_id": "client_1q8sn8pLHjqTU2g1UheJwJ7YWU6", - "user_id": "user_1n5BS00ns3t21GWIXiPJ0KcSe02", - "status": "active", - "last_active_at": 1616473411, - "expire_at": 1617078211, - "abandon_at": 1619065411 - } -] diff --git a/test/fixtures/all_users.json b/test/fixtures/all_users.json deleted file mode 100644 index 00c8479..0000000 --- a/test/fixtures/all_users.json +++ /dev/null @@ -1,88 +0,0 @@ -[ - { - "id": "user_1skey1AXIL5UvH5B6XdMWawkEsj", - "object": "user", - "username": null, - "first_name": "test", - "last_name": "test", - "gender": "", - "birthday": "", - "profile_image_url": "https://picsum.photos/id/237/400/300", - "primary_email_address_id": "idn_1skew1iRLggWHfguGccJ0JUOKwi", - "primary_phone_number_id": null, - "password_enabled": true, - "two_factor_enabled": false, - "email_addresses": [ - { - "id": "idn_1skew1iRLggWHfguGccJ0JUOKwi", - "object": "email_address", - "email_address": "developer@clerk.dev", - "verification": { - "status": "verified", - "strategy": "email_code", - "attempts": 1, - "expire_at": 1621421849 - }, - "linked_to": [] - } - ], - "phone_numbers": [ - { - "id": "idn_1skf5mpYloqE4DDzTCtQTpJ5k5L", - "object": "phone_number", - "phone_number": "+31600000000", - "reserved_for_second_factor": false, - "verification": { - "status": "verified", - "strategy": "phone_code", - "attempts": 1, - "expire_at": 1621421926 - }, - "linked_to": [] - } - ], - "external_accounts": [], - "public_metadata": {}, - "private_metadata": {}, - "created_at": 1621421265000, - "updated_at": 1621421326000, - "last_sign_in_at": null, - "last_active_at": 1700690400000 - }, - { - "id": "user_1skey1AXIL5UvH5B6XdMWawkEsX", - "object": "user", - "username": null, - "first_name": "test", - "last_name": "test", - "gender": "", - "birthday": "", - "profile_image_url": "https://picsum.photos/id/234/400/300", - "primary_email_address_id": "idn_1skew1iRLggWHfguGccJ0JUOKwJ", - "primary_phone_number_id": null, - "password_enabled": true, - "two_factor_enabled": false, - "email_addresses": [ - { - "id": "idn_1skew1iRLggWHfguGccJ0JUOKwi", - "object": "email_address", - "email_address": "developer2@clerk.dev", - "verification": { - "status": "verified", - "strategy": "email_code", - "attempts": 1, - "expire_at": 1621421849 - }, - "linked_to": [] - } - ], - "phone_numbers": [], - "external_accounts": [], - "public_metadata": {}, - "private_metadata": {}, - "created_at": 1621421265123, - "updated_at": 1621421326678, - "last_sign_in_at": 1701677564411, - "last_active_at": 1701734400000 - } -] diff --git a/test/fixtures/allowlist_identifier_1.json b/test/fixtures/allowlist_identifier_1.json deleted file mode 100644 index 1ce1b58..0000000 --- a/test/fixtures/allowlist_identifier_1.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "object": "allowlist_identifier", - "id": "alid_1sOWqxBnLKkD7Alxv5EymdOKjue", - "identifier": "+1655559004", - "created_at": 1620370000, - "updated_at": 1620370000 -} diff --git a/test/fixtures/allowlist_identifier_1_deleted.json b/test/fixtures/allowlist_identifier_1_deleted.json deleted file mode 100644 index 43b139e..0000000 --- a/test/fixtures/allowlist_identifier_1_deleted.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "alid_1", - "object": "allowlist_identifier", - "deleted": true -} diff --git a/test/fixtures/allowlist_toggle.json b/test/fixtures/allowlist_toggle.json deleted file mode 100644 index 5e19440..0000000 --- a/test/fixtures/allowlist_toggle.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "object": "instance", - "id": "ins_1rWjY3fNHDn5dYHmeJGyFB9ftlh", - "restricted_to_allowlist": true -} diff --git a/test/fixtures/client_1.json b/test/fixtures/client_1.json deleted file mode 100644 index 4223fda..0000000 --- a/test/fixtures/client_1.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "object": "client", - "id": "client_1", - "session_ids": [ - "sess_1q8u7QQhKOGRitdFGreHB00443j" - ], - "sign_in_attempt_id": null, - "sign_up_attempt_id": null, - "last_active_session_id": "sess_1q8u7QQhKOGRitdFGreHB00443j", - "created_at": 1616473358, - "updated_at": 1616473358 -} diff --git a/test/fixtures/email_address_1.json b/test/fixtures/email_address_1.json deleted file mode 100644 index 6dcee61..0000000 --- a/test/fixtures/email_address_1.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "id": "idn_email", - "object": "email_address", - "email_address": "john@doe.com", - "reserved": true, - "linked_to": [] -} diff --git a/test/fixtures/email_address_1_deleted.json b/test/fixtures/email_address_1_deleted.json deleted file mode 100644 index ec8880e..0000000 --- a/test/fixtures/email_address_1_deleted.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "object": "email_address", - "id": "idn_email", - "deleted": true -} diff --git a/test/fixtures/email_address_1_updated.json b/test/fixtures/email_address_1_updated.json deleted file mode 100644 index 3c21399..0000000 --- a/test/fixtures/email_address_1_updated.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "id": "idn_email", - "object": "email_address", - "email_address": "john@doe.com", - "reserved": true, - "verification": { - "status": "verified", - "strategy": "admin", - "attempts": null, - "expire_at": null - }, - "linked_to": [] -} diff --git a/test/fixtures/email_created.json b/test/fixtures/email_created.json deleted file mode 100644 index 639ca40..0000000 --- a/test/fixtures/email_created.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "id": "ema_1", - "object": "email", - "from_email_name": "support", - "to_email_address": "boss@clerk.dev", - "email_address_id": "idn_1n5AVtYAHNQY73d6dY6GVJt8gmD", - "subject": "green test", - "body": "this is a green test", - "status": "queued" -} diff --git a/test/fixtures/jwks.json b/test/fixtures/jwks.json deleted file mode 100644 index 9a79a4d..0000000 --- a/test/fixtures/jwks.json +++ /dev/null @@ -1 +0,0 @@ -{"keys":[{"use":"sig","kty":"RSA","kid":"ins_1v4uxFUhQHMqWyPdlihWSdGkKab","alg":"RS256","n":"7qFa2bcz6DvV893VawGXjvNjVp0S6uJqyL58DYPpRePVO8PxTvrAB_o7EHTCPO9Z3lgZgW-gMFsi4zc6wzv_1dSO6eiQixNo4Z0J9PJOSB5FLnuoDY0U3QwPb81I_J3eNjmt3WEcnHFkN4WlFrqbi_oY0-QKWSWI7R_jIECkTVhZTOpF6C4avDmL_XjP-RUtBnKsQbVzwm8OGOvjNucI9xTJrf3YFpan5P8Ix8R87IRZcYioaXsuWLYrHJamsP6coAbYaI3-xahJ6pWnAo3NT_PudWFq85ULhYHEThcU9sH-7Qbc0nuLB2z0vyUQgE3vXIVImONGFwxdYh9LbMCRhw","e":"AQAB"}]} diff --git a/test/fixtures/jwt_valid.json b/test/fixtures/jwt_valid.json deleted file mode 100644 index 7014264..0000000 --- a/test/fixtures/jwt_valid.json +++ /dev/null @@ -1 +0,0 @@ -eyJhbGciOiJSUzI1NiIsImtpZCI6Imluc18xdjR1eEZVaFFITXFXeVBkbGloV1NkR2tLYWIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJjbGVyayIsImVtYWlsIjoiZm9vQGJhci5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZXhwIjoxNjI3NTU0NzIyLCJmYW1pbHlfbmFtZSI6IkRvZSIsImdpdmVuX25hbWUiOiJKb2huIiwiaWF0IjoxNjI3NTU0NjU3LCJpc3MiOiJodHRwczovL2NsZXJrLmV4YW1wbGUuY29tIiwibmFtZSI6IkpvaG4iLCJwaWN0dXJlIjoiaHR0cHM6Ly9pbWFnZXMuZXhhbXBsZS5jb20vYXZhdGFyLnBuZyIsInN1YiI6InVzZXJfMXZDbXFkQXN5d25XbmhFeWY1MzBxY3pydElpIiwidXBkYXRlZF9hdCI6MTYyNzQ4MTAyM30.FQ-hTl8sJaquKmJPDEegP1_r7-yY4YLZAWTs40RKtaybzqJPll_tmiioxjDGyrUMtjwMls8N-C_WV2BB2XWAubsX2UhZXMz6wnWpVb76OUeoGXhQYH9f64MwvSoMlfTZUqtE5b_6-OBgtzmw8cJHjzxR9D6tjfC89o4e1_MtEV9h6ESy8pSTTF344xi4KjG-9TfPqiwUES5qrd5ho7z3ollu84hB05voEbToqkRFQrHEL-Loft1FlZVG9YTAkc3LOHqF21ofAgSL9ZVr7zxkPsGOfGb2kWyyfX6eFxk_NHvrUIEn9e_zR7mEspniJE4-DfQPOWeKMdYi1fU8BW-Eaw \ No newline at end of file diff --git a/test/fixtures/phone_number_1.json b/test/fixtures/phone_number_1.json deleted file mode 100644 index b0afbdf..0000000 --- a/test/fixtures/phone_number_1.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "id": "idn_phone", - "object": "phone_number", - "phone_number": "+15555555555", - "reserved_for_second_factor": false, - "default_second_factor": false, - "reserved": false, - "linked_to": [], - "backup_codes": null -} diff --git a/test/fixtures/phone_number_1_deleted.json b/test/fixtures/phone_number_1_deleted.json deleted file mode 100644 index 24f1cc6..0000000 --- a/test/fixtures/phone_number_1_deleted.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "object": "phone_number", - "id": "idn_phone", - "deleted": true -} diff --git a/test/fixtures/phone_number_1_updated.json b/test/fixtures/phone_number_1_updated.json deleted file mode 100644 index 58c6248..0000000 --- a/test/fixtures/phone_number_1_updated.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "id": "idn_phone", - "object": "phone_number", - "phone_number": "+15555555555", - "reserved_for_second_factor": false, - "default_second_factor": false, - "reserved": false, - "verification": { - "status": "verified", - "strategy": "admin", - "attempts": null, - "expire_at": null - }, - "linked_to": [], - "backup_codes": null -} diff --git a/test/fixtures/session_1.json b/test/fixtures/session_1.json deleted file mode 100644 index 7ed65d1..0000000 --- a/test/fixtures/session_1.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "object": "session", - "id": "sess_1", - "client_id": "client_1q8sn8pLHjqTU2g1UheJwJ7YWU6", - "user_id": "user_1n5BS00ns3t21GWIXiPJ0KcSe02", - "status": "active", - "last_active_at": 1616473411, - "expire_at": 1617078211, - "abandon_at": 1619065411 -} diff --git a/test/fixtures/testing_token_1.json b/test/fixtures/testing_token_1.json deleted file mode 100644 index ff7e0ac..0000000 --- a/test/fixtures/testing_token_1.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "object": "testing_token", - "token": "1713877310-c_3n2MvPu9PnXcuhBPZNao0LOXqK9A7YrnBn0HmIWyy", - "expires_at": 1713966600 -} diff --git a/test/fixtures/user_1.json b/test/fixtures/user_1.json deleted file mode 100644 index f173406..0000000 --- a/test/fixtures/user_1.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "id": "user_1", - "object": "user", - "username": null, - "first_name": "test", - "last_name": "test", - "gender": "", - "birthday": "", - "profile_image_url": "https://picsum.photos/id/237/400/300", - "primary_email_address_id": "idn_1skew1iRLggWHfguGccJ0JUOKwi", - "primary_phone_number_id": null, - "password_enabled": true, - "two_factor_enabled": false, - "email_addresses": [ - { - "id": "idn_1skew1iRLggWHfguGccJ0JUOKwi", - "object": "email_address", - "email_address": "developer@clerk.dev", - "verification": { - "status": "verified", - "strategy": "email_code", - "attempts": 1, - "expire_at": 1621421849 - }, - "linked_to": [] - } - ], - "phone_numbers": [ - { - "id": "idn_1skf5mpYloqE4DDzTCtQTpJ5k5L", - "object": "phone_number", - "phone_number": "+31600000000", - "reserved_for_second_factor": false, - "verification": { - "status": "verified", - "strategy": "phone_code", - "attempts": 1, - "expire_at": 1621421926 - }, - "linked_to": [] - } - ], - "external_accounts": [], - "public_metadata": {}, - "private_metadata": {}, - "created_at": 1621421265, - "updated_at": 1621421326 -} diff --git a/test/fixtures/user_1_deleted.json b/test/fixtures/user_1_deleted.json deleted file mode 100644 index fc9f224..0000000 --- a/test/fixtures/user_1_deleted.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "user_1", - "object": "user", - "deleted": true -} diff --git a/test/fixtures/user_1_updated.json b/test/fixtures/user_1_updated.json deleted file mode 100644 index e69f277..0000000 --- a/test/fixtures/user_1_updated.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "id": "user_1", - "object": "user", - "username": null, - "first_name": "Mary", - "last_name": "test", - "gender": "", - "birthday": "", - "profile_image_url": "https://picsum.photos/id/237/400/300", - "primary_email_address_id": "idn_1skew1iRLggWHfguGccJ0JUOKwi", - "primary_phone_number_id": null, - "password_enabled": true, - "two_factor_enabled": false, - "email_addresses": [ - { - "id": "idn_1skew1iRLggWHfguGccJ0JUOKwi", - "object": "email_address", - "email_address": "developer@clerk.dev", - "verification": { - "status": "verified", - "strategy": "email_code", - "attempts": 1, - "expire_at": 1621421849 - }, - "linked_to": [] - } - ], - "phone_numbers": [ - { - "id": "idn_1skf5mpYloqE4DDzTCtQTpJ5k5L", - "object": "phone_number", - "phone_number": "+31600000000", - "reserved_for_second_factor": false, - "verification": { - "status": "verified", - "strategy": "phone_code", - "attempts": 1, - "expire_at": 1621421926 - }, - "linked_to": [] - } - ], - "external_accounts": [], - "public_metadata": {}, - "private_metadata": {}, - "created_at": 1621421265, - "updated_at": 1621421326 -} diff --git a/test/fixtures/users_oauth_access_token.json b/test/fixtures/users_oauth_access_token.json deleted file mode 100644 index 7d82b5c..0000000 --- a/test/fixtures/users_oauth_access_token.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "token": "xxxx", - "provider": "hubspot", - "scopes": [ - "oauth", - "contacts" - ] -} diff --git a/test/resources/allowlist_identifiers_test.rb b/test/resources/allowlist_identifiers_test.rb deleted file mode 100644 index 4ce1464..0000000 --- a/test/resources/allowlist_identifiers_test.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::AllowlistIdentifierTest < Minitest::Test - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/allowlist_identifiers") { json_ok("all_allowlist_identifiers") } - stub.post("/allowlist_identifiers") { json_ok("allowlist_identifier_1") } - stub.delete("/allowlist_identifiers/alid_1") { json_ok("allowlist_identifier_1_deleted") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_all_allowlist_identifiers - allowlist_identifiers = mock_sdk.allowlist_identifiers.all - assert_equal ["allowlist_identifier"], allowlist_identifiers.map { |h| h.dig("object") } - end - - def test_delete_allowlist_identifier - user = mock_sdk.allowlist_identifiers.delete("alid_1") - assert_equal true, user["deleted"] - assert_equal "allowlist_identifier", user["object"] - assert_equal "alid_1", user["id"] - end -end diff --git a/test/resources/allowlist_test.rb b/test/resources/allowlist_test.rb deleted file mode 100644 index 5d71340..0000000 --- a/test/resources/allowlist_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::AllowlistTest < Minitest::Test - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.patch("/beta_features/allowlist") { json_ok("allowlist_toggle") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_toggle_allowlist - resp = mock_sdk.allowlist.update({restricted_to_allowlist: true}) - assert_equal true, resp["restricted_to_allowlist"] - end -end diff --git a/test/resources/clients_test.rb b/test/resources/clients_test.rb deleted file mode 100644 index 57c1ae8..0000000 --- a/test/resources/clients_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::ClientsTest < Minitest::Test - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/clients") { json_ok("all_clients") } - stub.get("/clients/client_1") { json_ok("client_1") } - stub.post("/clients/verify") { json_ok("client_1") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_all_clients - sess = mock_sdk.clients.all - assert_equal ["client"], sess.map { |h| h.dig("object") } - end - - def test_find_client - sess = mock_sdk.clients.find("client_1") - assert_equal "client", sess["object"] - assert_equal "client_1", sess["id"] - end - - def test_verify_client - sess = mock_sdk.clients.verify_token("token_1") - assert_equal "client", sess["object"] - assert_equal "client_1", sess["id"] - end -end diff --git a/test/resources/email_addresses_test.rb b/test/resources/email_addresses_test.rb deleted file mode 100644 index ec6bad5..0000000 --- a/test/resources/email_addresses_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::EmailAddressTest < Minitest::Test - - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/email_addresses/idn_email") { json_ok("email_address_1") } - stub.post("/email_addresses") { json_ok("email_address_1") } - stub.patch("/email_addresses/idn_email") { json_ok("email_address_1_updated") } - stub.delete("/email_addresses/idn_email") { json_ok("email_address_1_deleted") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_find_email_address - email_address_id = "idn_email" - email_address = mock_sdk.email_addresses.find(email_address_id) - assert_equal "email_address", email_address["object"] - assert_equal email_address_id, email_address["id"] - assert_equal "john@doe.com", email_address["email_address"] - assert_nil email_address["verification"] - end - - def test_create_email_address - email_address = mock_sdk.email_addresses.create(user_id: "user_abcdefg", email_address: "") - assert_equal "email_address", email_address["object"] - assert_equal "john@doe.com", email_address["email_address"] - assert_nil email_address["verification"] - end - - def test_update_email_address - email_address_id = "idn_email" - email_address = mock_sdk.email_addresses.update(email_address_id, verified: true) - assert_equal "email_address", email_address["object"] - assert_equal email_address_id, email_address["id"] - assert_equal "john@doe.com", email_address["email_address"] - refute_nil email_address["verification"] - end - - def test_delete_email_address - email_address_id = "idn_email" - deleted_object = mock_sdk.email_addresses.delete(email_address_id) - assert_equal "email_address", deleted_object["object"] - assert_equal email_address_id, deleted_object["id"] - assert deleted_object["deleted"] - end - -end diff --git a/test/resources/emails_test.rb b/test/resources/emails_test.rb deleted file mode 100644 index 3ba7077..0000000 --- a/test/resources/emails_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::EmailsTest < Minitest::Test - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.post("/emails") { json_ok("email_created") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_create_email - resp = mock_sdk.emails.create({ - email_address_id: "idn_xxx", - from_email_name: "noreply", - subject: "hi", - body: "hello", - }) - assert_equal "email", resp["object"] - end -end diff --git a/test/resources/phone_numbers_test.rb b/test/resources/phone_numbers_test.rb deleted file mode 100644 index fe5039c..0000000 --- a/test/resources/phone_numbers_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::PhoneNumbersTest < Minitest::Test - - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/phone_numbers/idn_phone") { json_ok("phone_number_1") } - stub.post("/phone_numbers") { json_ok("phone_number_1") } - stub.patch("/phone_numbers/idn_phone") { json_ok("phone_number_1_updated") } - stub.delete("/phone_numbers/idn_phone") { json_ok("phone_number_1_deleted") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_find_phone_number - phone_number_id = "idn_phone" - phone_number = mock_sdk.phone_numbers.find(phone_number_id) - assert_equal "phone_number", phone_number["object"] - assert_equal phone_number_id, phone_number["id"] - assert_equal "+15555555555", phone_number["phone_number"] - assert_nil phone_number["verification"] - end - - def test_create_phone_number - phone_number = mock_sdk.phone_numbers.create(user_id: "user_abcdefg", phone_number: "+15555555555") - assert_equal "phone_number", phone_number["object"] - assert_equal "+15555555555", phone_number["phone_number"] - assert_nil phone_number["verification"] - end - - def test_update_phone_number - phone_number_id = "idn_phone" - phone_number = mock_sdk.phone_numbers.update(phone_number_id, verified: true) - assert_equal "phone_number", phone_number["object"] - assert_equal phone_number_id, phone_number["id"] - assert_equal "+15555555555", phone_number["phone_number"] - refute_nil phone_number["verification"] - end - - def test_delete_phone_number - phone_number_id = "idn_phone" - deleted_object = mock_sdk.phone_numbers.delete(phone_number_id) - assert_equal "phone_number", deleted_object["object"] - assert_equal phone_number_id, deleted_object["id"] - assert deleted_object["deleted"] - end - -end diff --git a/test/resources/sessions_test.rb b/test/resources/sessions_test.rb deleted file mode 100644 index 6460f98..0000000 --- a/test/resources/sessions_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::SessionsTest < Minitest::Test - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/sessions") { json_ok("all_sessions") } - stub.get("/sessions/sess_1") { json_ok("session_1") } - stub.post("/sessions/sess_1/revoke") { json_ok("session_1") } - stub.post("/sessions/sess_1/verify") { json_ok("session_1") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_all_sessions - sess = mock_sdk.sessions.all - assert_equal ["session"], sess.map { |h| h.dig("object") } - end - - def test_find_session - sess = mock_sdk.sessions.find("sess_1") - assert_equal "session", sess["object"] - assert_equal "sess_1", sess["id"] - end - - def test_revoke_session - sess = mock_sdk.sessions.revoke("sess_1") - assert_equal "session", sess["object"] - assert_equal "sess_1", sess["id"] - end - - def test_verify_session - sess = mock_sdk.sessions.verify_token("sess_1", "token_1") - assert_equal "session", sess["object"] - assert_equal "sess_1", sess["id"] - end -end diff --git a/test/resources/testing_tokens_test.rb b/test/resources/testing_tokens_test.rb deleted file mode 100644 index e7f241b..0000000 --- a/test/resources/testing_tokens_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::TestingTokensTest < Minitest::Test - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.post("/testing_tokens") { json_ok("testing_token_1") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_create_testing_token - response = mock_sdk.testing_tokens.create - - assert_equal "testing_token", response["object"] - assert_equal "1713877310-c_3n2MvPu9PnXcuhBPZNao0LOXqK9A7YrnBn0HmIWyy", - response["token"] - assert_equal 1713966600, response["expires_at"] - - end -end diff --git a/test/resources/users_test.rb b/test/resources/users_test.rb deleted file mode 100644 index 7c66a36..0000000 --- a/test/resources/users_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class Clerk::Resources::UsersTest < Minitest::Test - def mock_sdk - faraday = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/users") { json_ok("all_users") } - stub.get("/users?limit=10") { json_ok("all_users") } - stub.get("/users/user_1") { json_ok("user_1") } - stub.patch("/users/user_1") { json_ok("user_1_updated") } - stub.delete("/users/user_1") { json_ok("user_1_deleted") } - stub.get("/users/unknown_id") { json_404 } - stub.get("/users/user_1/oauth_access_tokens/hubspot") { json_ok("users_oauth_access_token") } - end - end - - ::Clerk::SDK.new(connection: faraday) - end - - def test_all_users - users = mock_sdk.users.all - assert_equal ["user", "user"], users.map { |h| h.dig("object") } - end - - def test_all_users_query_params - users = mock_sdk.users.all(limit: 1) - assert_equal ["user", "user"], users.map { |h| h.dig("object") } - end - - def test_find_user - user = mock_sdk.users.find("user_1") - assert_equal "user", user["object"] - assert_equal "user_1", user["id"] - end - - def test_update_user - user = mock_sdk.users.update("user_1", {first_name: "Mary"}) - assert_equal "Mary", user["first_name"] - assert_equal "user_1", user["id"] - end - - def test_delete_user - user = mock_sdk.users.delete("user_1") - assert_equal true, user["deleted"] - assert_equal "user", user["object"] - assert_equal "user_1", user["id"] - end - - def test_find_user_404 - assert_raises Clerk::Errors::Fatal do - mock_sdk.users.find("unknown_id") - end - end - - def test_oauth_access_token - response = mock_sdk.users.oauth_access_token("user_1", "hubspot") - assert_equal "xxxx", response["token"] - assert_equal "hubspot", response["provider"] - assert_equal ["oauth", "contacts"], response["scopes"] - end -end diff --git a/test/sdk_test.rb b/test/sdk_test.rb deleted file mode 100644 index 01c8d98..0000000 --- a/test/sdk_test.rb +++ /dev/null @@ -1,137 +0,0 @@ -# frozen_string_literal: true -# -require "test_helper" - -class Clerk::SdkTest < Minitest::Test - TIME_WHEN_JWT_IS_VALID = Time.new(2021, 7, 29, 13, 31, 30, "+03:00") - TIME_WHEN_JWT_HAS_EXPIRED = Time.new(2021, 7, 29, 13, 33, 00, "+03:00") - - def test_sdk_init_without_config - sdk = ::Clerk::SDK.new - assert sdk - end - - def test_application_json_encoding - unparsed_payload = { a: "b", c: ["d"], d: { e: 3 } } - json_payload = '{"a":"b","c":["d"],"d":{"e":3}}' - - conn = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.patch("/users/user_1", json_payload, { "Content-Type" => "application/json" } ) do |env| - parsed = JSON.parse(env.request_body) - parsed["a"] = "b" - parsed["c"] = ["d"] - parsed["d"] = { "e" => 3 } - - json_ok("user_1_updated") - end - end - end - - sdk = ::Clerk::SDK.new(connection: conn) - user = sdk.users.update("user_1", unparsed_payload) - - assert_equal "Mary", user["first_name"] - assert_equal "user_1", user["id"] - end - - def test_no_api_key_raises_on_api_call - sdk = ::Clerk::SDK.new - assert_raises ArgumentError do - sdk.users.find("x") - end - end - - def test_verify_token - conn = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/jwks") { json_ok("jwks") } - end - end - - sdk = ::Clerk::SDK.new(connection: conn) - valid_jwt = json_fixture("jwt_valid") - - Timecop.freeze(TIME_WHEN_JWT_HAS_EXPIRED) do - assert_raises JWT::ExpiredSignature do - sdk.verify_token(valid_jwt) - end - end - - Timecop.freeze(TIME_WHEN_JWT_IS_VALID) do - assert sdk.verify_token(valid_jwt) - - assert_raises JWT::IncorrectAlgorithm do - sdk.verify_token(valid_jwt, algorithms: ["RS512"]) - end - - assert_raises JWT::VerificationError do - malformed_token = json_fixture("jwt_valid")[0..-2] - sdk.verify_token(malformed_token) - end - end - end - - def test_verify_token_jwks_cache - jwks_endpoint_hits = 0 - - conn = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/jwks") do - jwks_endpoint_hits += 1 - json_ok("jwks") - end - end - end - - sdk = ::Clerk::SDK.new(connection: conn) - - Timecop.freeze(TIME_WHEN_JWT_IS_VALID) do - sdk.verify_token(json_fixture("jwt_valid"), force_refresh_jwks: true) - assert_equal 1, jwks_endpoint_hits - - sdk.verify_token(json_fixture("jwt_valid")) - assert_equal 1, jwks_endpoint_hits - - sdk.verify_token(json_fixture("jwt_valid"), force_refresh_jwks: true) - assert_equal 2, jwks_endpoint_hits - - sdk.verify_token(json_fixture("jwt_valid")) - assert_equal 2, jwks_endpoint_hits - end - - # cache expired - Timecop.freeze(TIME_WHEN_JWT_IS_VALID+Clerk::SDK::JWKS_CACHE_LIFETIME+1) do - begin - sdk.verify_token(json_fixture("jwt_valid")) - rescue JWT::ExpiredSignature - # we know the token is going to be expired in this travelled to time - end - - assert_equal 3, jwks_endpoint_hits - end - - # assert that if the server (BAPI) returns an error to the JWKS request - # (i.e. BAPI was down momentarily) and therefore the received token couldn't - # be verified, then we're going to try one more time - jwks_endpoint_hits = 0 - conn = Faraday.new do |faraday| - faraday.adapter :test do |stub| - stub.get("/jwks") do - jwks_endpoint_hits += 1 - jwks_endpoint_hits < 2 ? json_404 : json_ok("jwks") - end - end - end - - sdk = ::Clerk::SDK.new(connection: conn) - Timecop.freeze(TIME_WHEN_JWT_IS_VALID) do - claims = sdk.verify_token(json_fixture("jwt_valid"), force_refresh_jwks: true) - assert_equal 2, jwks_endpoint_hits - assert_equal "foo@bar.com", claims["email"] - - sdk.verify_token(json_fixture("jwt_valid")) - assert_equal 2, jwks_endpoint_hits # cached response - end - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 5fff820..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -$LOAD_PATH.unshift File.expand_path("../lib", __dir__) -require "clerk" -require "timecop" - -require "minitest/autorun" - -FIXTURE_BASE = File.expand_path("fixtures", __dir__) - -def json_fixture(file) - File.read(File.join(FIXTURE_BASE, "#{file}.json")) -end - -def json_ok(file) - [200, {"Content-Type" => "application/json"}, json_fixture(file)] -end - -def json_404 - [404, {"Content-Type" => "application/json"}, JSON.dump( - {"errors" => [ - {"message" => "not found"} - ]} - )] -end