Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
araluce committed Sep 21, 2021
1 parent d63079d commit aeda915
Show file tree
Hide file tree
Showing 35 changed files with 772 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
== 0.1.0 / 2021-09-21
== 0.1.1 / 2021-09-21
* Changed required ruby version from `>= 2.3.0` to `>= 2.4.0`
* Minitest
* Minor fixes

== 0.1.0 / 2021-09-21
* Birthday!
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Calendly API Rubygem [WIP] [Waiting for testing]
# Calendly API Rubygem

Easy and complete rubygem for [Calendly](https://calendly.com/). Currently supports [API v2](https://calendly.stoplight.io/docs/api-docs).

Expand Down
2 changes: 1 addition & 1 deletion lib/calendly/resources/event_invitees.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def list(event_uuid:, **params)
end

def retrieve(event_uuid:, invitee_uuid:)
EventInvitee.new get_request("scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}").body.dig("resource"), client: client
EventInvitee.new get_request("scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}").body, client: client
end
end
end
7 changes: 3 additions & 4 deletions lib/calendly/resources/scheduling_links.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Calendly
class SchedulingLinkResource < Resource
def create(owner_uri:, max_event_count:, owner_type: "EventType", **attributes)
body = { owner: owner_uri, max_event_count: max_event_count, owner_type: owner_type }.merge(attributes).compact
response = post_request("scheduling_links", body: body).body.dig("resource")
SchedulingLink.new response, client: client
def create(owner_uri:, max_event_count:, owner_type: "EventType")
body = { owner: owner_uri, max_event_count: max_event_count, owner_type: owner_type }
SchedulingLink.new post_request("scheduling_links", body: body).body.dig("resource"), client: client
end
end
end
7 changes: 3 additions & 4 deletions lib/calendly/resources/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ def list(organization_uri:, scope:, **params)
Collection.from_response(response, key: "collection", type: Webhook, client: client)
end

def create(resource_uri:, events:, organization_uri:, user_uri: nil, scope:, **attributes)
body = { url: resource_uri, events: events, organization: organization_uri, user: user_uri, scope: scope }.merge(attributes).compact
response = post_request("webhook_subscriptions", body: body).body.dig("resource")
Webhook.new response, client: client
def create(resource_uri:, events:, organization_uri:, user_uri: nil, scope:, signing_key: nil)
body = { url: resource_uri, events: events, organization: organization_uri, user: user_uri, scope: scope, signing_key: signing_key }.compact
Webhook.new post_request("webhook_subscriptions", body: body).body.dig("resource"), client: client
end

def retrieve(webhook_uuid:)
Expand Down
2 changes: 1 addition & 1 deletion lib/calendly/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Calendly
VERSION = "0.1.0"
VERSION = "0.1.1"
end
8 changes: 8 additions & 0 deletions test/calendly/client_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "test_helper"

class ClientTest < Minitest::Test
def test_api_key
client = Calendly::Client.new api_key: "test"
assert_equal "test", client.api_key
end
end
21 changes: 21 additions & 0 deletions test/calendly/object_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "test_helper"

class ObjectTest < Minitest::Test
def test_creating_object_from_hash
assert_equal "bar", Calendly::Object.new(foo: "bar").foo
end

def test_nested_hash
assert_equal "foobar", Calendly::Object.new(foo: {bar: {baz: "foobar"}}, client: nil).foo.bar.baz
end

def test_nested_number
assert_equal 1, Calendly::Object.new(foo: {bar: 1}, client: nil).foo.bar
end

def test_array
object = Calendly::Object.new(foo: [{bar: :baz}], client: nil)
assert_equal OpenStruct, object.foo.first.class
assert_equal :baz, object.foo.first.bar
end
end
12 changes: 12 additions & 0 deletions test/calendly/resources/data_compliance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "test_helper"

class DataComplianceResourceTest < Minitest::Test
def test_delete_invitee_data
body = { emails: %w[test@test.com test2@test.com] }
stub = stub_request("data_compliance/deletion/invitees", method: :post, body: body, response: stub_response(fixture: "data_compliance/delete_invitee_data", status: 202))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
assert client.data_compliance.delete_invitee_data(**body)
end
end
29 changes: 29 additions & 0 deletions test/calendly/resources/event_invitees_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require "test_helper"

class EventInviteesResourceTest < Minitest::Test
def test_list
event_uuid = "ABCDABCDABCDABCD"
stub = stub_request("scheduled_events/#{event_uuid}/invitees", response: stub_response(fixture: "event_invitees/list"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
event_invitees = client.event_invitees.list(event_uuid: event_uuid)

assert_equal Calendly::Collection, event_invitees.class
assert_equal Calendly::EventInvitee, event_invitees.data.first.class
assert_equal 1, event_invitees.count
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", event_invitees.next_page_token
end

def test_retrieve
event_uuid = "AAAAAAAAAAAAAAAA"
invitee_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("scheduled_events/#{event_uuid}/invitees/#{invitee_uuid}", response: stub_response(fixture: "event_invitees/retrieve"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
event_invitee = client.event_invitees.retrieve(event_uuid: event_uuid, invitee_uuid: invitee_uuid)

assert_equal Calendly::EventInvitee, event_invitee.class
assert_equal "https://api.calendly.com/api/v2/scheduled_events/ABCDABCDABCDABCD/invitees/ABCDABCDABCDABCD", event_invitee.uri
assert_equal "John Doe", event_invitee.name
end
end
31 changes: 31 additions & 0 deletions test/calendly/resources/event_types_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "test_helper"

class EventTypesResourceTest < Minitest::Test
def test_list
user_uri = "https://api.calendly.com/users/AAAAAAAAAAAAAAAA"
organization_uri = "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA"
stub = stub_request("event_types?user=#{user_uri}&organization=#{organization_uri}", response: stub_response(fixture: "event_types/list"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
event_types = client.event_types.list(user_uri: user_uri, organization_uri: organization_uri)

assert_equal Calendly::Collection, event_types.class
assert_equal Calendly::EventType, event_types.data.first.class
assert_equal 1, event_types.count
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", event_types.next_page_token
end

def test_retrieve
event_type_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("event_types/#{event_type_uuid}", response: stub_response(fixture: "event_types/retrieve"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
event_type = client.event_types.retrieve(event_type_uuid: event_type_uuid)

assert_equal Calendly::EventType, event_type.class
assert_equal "https://api.calendly.com/event_types/AAAAAAAAAAAAAAAA", event_type.uri
assert_equal "15 Minute Meeting", event_type.name
assert_equal "acmesales", event_type.slug
assert_equal 30, event_type.duration
end
end
29 changes: 29 additions & 0 deletions test/calendly/resources/events_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require "test_helper"

class EventsResourceTest < Minitest::Test
def test_list
user_uri = "https://api.calendly.com/users/AAAAAAAAAAAAAAAA"
organization_uri = "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA"
stub = stub_request("scheduled_events?user=#{user_uri}&organization=#{organization_uri}", response: stub_response(fixture: "events/list"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
events = client.events.list(user_uri: user_uri, organization_uri: organization_uri)

assert_equal Calendly::Collection, events.class
assert_equal Calendly::Event, events.data.first.class
assert_equal 1, events.count
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", events.next_page_token
end

def test_retrieve
event_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("scheduled_events/#{event_uuid}", response: stub_response(fixture: "events/retrieve"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
event = client.events.retrieve(event_uuid: event_uuid)

assert_equal Calendly::Event, event.class
assert_equal "https://api.calendly.com/scheduled_events/GBGBDCAADAEDCRZ2", event.uri
assert_equal "15 Minute Meeting", event.name
end
end
77 changes: 77 additions & 0 deletions test/calendly/resources/organizations_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: true

require "test_helper"

class OrganizationsResourceTest < Minitest::Test
def test_invite
organization_uuid = "ABCDABCDABCDABCD"
email = "email@example.com"
stub = stub_request("organizations/#{organization_uuid}/invitations", method: :post, body: { email: email }, response: stub_response(fixture: "organizations/invite", status: 201))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
invitation = client.organizations.invite(organization_uuid: organization_uuid, email: email)

assert_equal Calendly::Invitation, invitation.class
assert_equal email, invitation.email
end

def test_list_invitations
organization_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("organizations/#{organization_uuid}/invitations", response: stub_response(fixture: "organizations/list_invitations"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
invitations = client.organizations.list_invitations(organization_uuid: organization_uuid)

assert_equal Calendly::Collection, invitations.class
assert_equal Calendly::Invitation, invitations.data.first.class
assert_equal 1, invitations.count
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", invitations.next_page_token
end

def test_list_memberships
user_uri = "AAAAAAAAAAAAAAAA"
organization_uri = "AAAAAAAAAAAAAAAA"
stub = stub_request("organization_memberships?user=#{user_uri}&organization=#{organization_uri}", response: stub_response(fixture: "organizations/list_memberships"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
memberships = client.organizations.list_memberships(user_uri: user_uri, organization_uri: organization_uri)

assert_equal Calendly::Collection, memberships.class
assert_equal Calendly::Membership, memberships.data.first.class
assert_equal 1, memberships.count
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", memberships.next_page_token
end

def test_retrieve_invitation
organization_uuid = "AAAAAAAAAAAAAAAA"
invitation_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("organizations/#{organization_uuid}/invitations/#{invitation_uuid}", response: stub_response(fixture: "organizations/retrieve_invitation"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
invitation = client.organizations.retrieve_invitation(organization_uuid: organization_uuid, invitation_uuid: invitation_uuid)

assert_equal Calendly::Invitation, invitation.class
assert_equal "test@example.com", invitation.email
end

def test_retrieve_membership
membership_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("organization_memberships/#{membership_uuid}", response: stub_response(fixture: "organizations/retrieve_membership"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
membership = client.organizations.retrieve_membership(membership_uuid: membership_uuid)

assert_equal Calendly::Membership, membership.class
assert_equal "test@example.com", membership.user.email
end

def test_revoke_invitation
organization_uuid = "AAAAAAAAAAAAAAAA"
invitation_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("organizations/#{organization_uuid}/invitations/#{invitation_uuid}", method: :delete, response: stub_response(fixture: "organizations/revoke_invitation", status: 204))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
assert client.organizations.revoke_invitation(organization_uuid: organization_uuid, invitation_uuid: invitation_uuid)
end

def test_remove_user
membership_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("organization_memberships/#{membership_uuid}", method: :delete, response: stub_response(fixture: "organizations/remove_user", status: 204))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
assert client.organizations.remove_user(membership_uuid: membership_uuid)
end
end
18 changes: 18 additions & 0 deletions test/calendly/resources/users_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "test_helper"

class UsersResourceTest < Minitest::Test
def test_retrieve
user_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("users/#{user_uuid}", response: stub_response(fixture: "users/retrieve"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
user = client.users.retrieve(user_uuid: user_uuid)

assert_equal Calendly::User, user.class
assert_equal "https://api.calendly.com/users/AAAAAAAAAAAAAAAA", user.uri
assert_equal "John Doe", user.name
assert_equal "acmesales", user.slug
assert_equal "test@example.com", user.email
end
end
35 changes: 35 additions & 0 deletions test/calendly/resources/webhooks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require "test_helper"

class WebhooksResourceTest < Minitest::Test
def test_list
organization_uri = "https://api.calendly.com/organizations/AAAAAAAAAAAAAAAA"
scope = "user"
stub = stub_request("webhook_subscriptions?organization=#{organization_uri}&scope=#{scope}", response: stub_response(fixture: "webhooks/list"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
webhooks = client.webhooks.list(organization_uri: organization_uri, scope: scope)

assert_equal Calendly::Collection, webhooks.class
assert_equal Calendly::Webhook, webhooks.data.first.class
assert_equal 1, webhooks.count
assert_equal "sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi", webhooks.next_page_token
end

def test_retrieve
webhook_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("webhook_subscriptions/#{webhook_uuid}", response: stub_response(fixture: "webhooks/retrieve"))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
webhook = client.webhooks.retrieve(webhook_uuid: webhook_uuid)

assert_equal Calendly::Webhook, webhook.class
assert_equal "user", webhook.scope
end

def test_delete
webhook_uuid = "AAAAAAAAAAAAAAAA"
stub = stub_request("webhook_subscriptions/#{webhook_uuid}", method: :delete, response: stub_response(fixture: "webhooks/delete", status: 204))
client = Calendly::Client.new(api_key: "fake", adapter: :test, stubs: stub)
assert client.webhooks.delete(webhook_uuid: webhook_uuid)
end
end
4 changes: 0 additions & 4 deletions test/calendly_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ class CalendlyTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::Calendly::VERSION
end

def test_it_does_something_useful
assert false
end
end
1 change: 1 addition & 0 deletions test/fixtures/data_compliance/delete_invitee_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
58 changes: 58 additions & 0 deletions test/fixtures/event_invitees/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"collection": [
{
"cancel_url": "https://calendly.com/cancellations/AAAAAAAAAAAAAAAA",
"created_at": "2020-11-23T17:51:18.327602Z",
"email": "test@example.com",
"event": "https://api.calendly.com/scheduled_events/AAAAAAAAAAAAAAAA",
"name": "John Doe",
"new_invitee": null,
"old_invitee": null,
"questions_and_answers": [
{
"answer": "radio button answer",
"position": 0,
"question": "Question with Radio Buttons answer type"
},
{
"answer": "Multiple line\nAnswer",
"position": 1,
"question": "Question with Multiple Lines answer type"
},
{
"answer": "Answer 1\nAnswer 2\nAnswer 3",
"position": 2,
"question": "Question with Checkboxes answer type"
}
],
"reschedule_url": "https://calendly.com/reschedulings/AAAAAAAAAAAAAAAA",
"rescheduled": false,
"status": "active",
"text_reminder_number": null,
"timezone": "America/New_York",
"tracking": {
"utm_campaign": null,
"utm_source": null,
"utm_medium": null,
"utm_content": null,
"utm_term": null,
"salesforce_uuid": null
},
"updated_at": "2020-11-23T17:51:18.341657Z",
"uri": "https://api.calendly.com/scheduled_events/AAAAAAAAAAAAAAAA/invitees/AAAAAAAAAAAAAAAA",
"canceled": false,
"payment": {
"external_id": "ch_AAAAAAAAAAAAAAAAAAAAAAAA",
"provider": "stripe",
"amount": 1234.56,
"currency": "USD",
"terms": "sample terms of payment (up to 1,024 characters)",
"successful": true
}
}
],
"pagination": {
"count": 1,
"next_page": "https://calendly.com/scheduled_events/AAAAAAAAAAAAAAAA/invitees?count=1&page_token=sNjq4TvMDfUHEl7zHRR0k0E1PCEJWvdi"
}
}
Loading

0 comments on commit aeda915

Please sign in to comment.