Skip to content

Commit

Permalink
Update Companies endpoint to reflect API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppostma committed Aug 13, 2024
1 parent d95f27f commit 8735c78
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
10 changes: 10 additions & 0 deletions lib/kentaa/api/resources/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def total_donations
data[:total_donations]
end

def reserved_spots
data[:reserved_spots]
end

def target_amount_achieved?
data[:target_amount_achieved]
end
Expand Down Expand Up @@ -178,9 +182,15 @@ def external_reference
end

def commerce_number
Kentaa::Api::Deprecation.warn('#commerce_number is deprecated.', caller)

data[:commerce_number]
end

def total_company_members
data[:total_company_members]
end

def consents
@consents ||= begin
consents = []
Expand Down
8 changes: 8 additions & 0 deletions lib/kentaa/api/resources/company_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def title
def description
data[:description]
end

def reservation_type
data[:reservation_type]
end

def reservation_limit
data[:reservation_limit]
end
end
end
end
Expand Down
13 changes: 9 additions & 4 deletions spec/fixtures/responses/companies.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
"title": "Vero aspernatur dolores et excepturi.",
"description": "Cum odio est. Consequuntur occaecati sapiente molestiae quam recusandae possimus aut. Ratione cum harum beatae ad repellat minus.",
"commerce_number": "12345678",
"total_company_members": 2,
"target_amount": 2000,
"total_amount": "225.0",
"total_donations": 4,
"reserved_spots": 10,
"target_amount_achieved": false,
"visible": true,
"countable": true,
Expand Down Expand Up @@ -80,7 +82,8 @@
"city": "Arnhem",
"country": "NL",
"phone": "0262616240",
"gender": "male"
"gender": "male",
"locale": "nl"
},
"photos": [
{
Expand Down Expand Up @@ -109,11 +112,13 @@
],
"package": {
"id": 1,
"amount": 10,
"amount": "10.0",
"title": "Package title",
"description": "Package description",
"created_at": "2015-08-26T14:50:16Z",
"updated_at": "2015-08-26T14:50:20Z"
"updated_at": "2015-08-26T14:50:20Z",
"reservation_type": "specific",
"reservation_limit": 10
},
"consents": [
{
Expand Down Expand Up @@ -147,4 +152,4 @@
"total_pages": 17,
"per_page": 2,
"current_page": 1
}
}
12 changes: 8 additions & 4 deletions spec/fixtures/responses/company.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
"title": "Vero aspernatur dolores et excepturi.",
"description": "Cum odio est. Consequuntur occaecati sapiente molestiae quam recusandae possimus aut. Ratione cum harum beatae ad repellat minus.",
"commerce_number": "12345678",
"total_company_members": 2,
"target_amount": 2000,
"total_amount": "225.0",
"total_donations": 4,
"reserved_spots": 10,
"target_amount_achieved": false,
"visible": true,
"countable": true,
Expand Down Expand Up @@ -108,12 +110,14 @@
],
"package": {
"id": 1,
"amount": 10,
"amount": "10.0",
"title": "Package title",
"description": "Package description",
"created_at": "2015-08-26T14:50:16Z",
"updated_at": "2015-08-26T14:50:20Z"
},
"updated_at": "2015-08-26T14:50:20Z",
"reservation_type": "specific",
"reservation_limit": 10
},
"consents": [
{
"consent_type": "terms_conditions",
Expand All @@ -135,4 +139,4 @@
}
]
}
}
}
14 changes: 14 additions & 0 deletions spec/kentaa/api/resources/company_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
end
end

describe '#total_company_members' do
it 'returns the total number of company members' do
expect(response.total_company_members).to eq(2)
end
end

describe '#slug' do
it 'returns the slug' do
expect(response.slug).to eq('asperiores-beatae-voluptate-qui')
Expand Down Expand Up @@ -117,6 +123,12 @@
end
end

describe '#reserved_spots' do
it 'returns the number of reserved spots' do
expect(response.reserved_spots).to eq(10)
end
end

describe '#target_amount_achieved?' do
it 'returns false when target amount not achieved' do
expect(response.target_amount_achieved?).to be false
Expand Down Expand Up @@ -218,6 +230,8 @@
expect(package.amount).to eq(10)
expect(package.title).to eq('Package title')
expect(package.description).to eq('Package description')
expect(package.reservation_type).to eq('specific')
expect(package.reservation_limit).to eq(10)
end
end

Expand Down

0 comments on commit 8735c78

Please sign in to comment.