-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Membership: Query memberships of an organization
- Loading branch information
Showing
5 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
class MembershipsResolver < GraphQL::Schema::Resolver | ||
include AuthenticableApiUser | ||
include RequiredOrganization | ||
|
||
description 'Query memberships of an organization' | ||
|
||
argument :page, Integer, required: false | ||
argument :limit, Integer, required: false | ||
|
||
type Types::MembershipType.collection_type, null: false | ||
|
||
def resolve(page: nil, limit: nil) | ||
validate_organization! | ||
|
||
current_organization | ||
.memberships | ||
.active | ||
.page(page) | ||
.per(limit) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Resolvers::MembershipsResolver, type: :graphql do | ||
let(:query) do | ||
<<~GQL | ||
query { | ||
memberships(limit: 5) { | ||
collection { id } | ||
metadata { currentPage, totalCount } | ||
} | ||
} | ||
GQL | ||
end | ||
|
||
let(:membership) { create(:membership) } | ||
let(:organization) { membership.organization } | ||
|
||
it 'returns a list of memberships' do | ||
result = execute_graphql( | ||
current_user: membership.user, | ||
current_organization: organization, | ||
query: query, | ||
) | ||
|
||
memberships_response = result['data']['memberships'] | ||
|
||
aggregate_failures do | ||
expect(memberships_response['collection'].count).to eq(organization.memberships.count) | ||
expect(memberships_response['collection'].first['id']).to eq(membership.id) | ||
|
||
expect(memberships_response['metadata']['currentPage']).to eq(1) | ||
expect(memberships_response['metadata']['totalCount']).to eq(1) | ||
end | ||
end | ||
|
||
context 'without current organization' do | ||
it 'returns an error' do | ||
result = execute_graphql( | ||
current_user: membership.user, | ||
query: query, | ||
) | ||
|
||
expect_graphql_error( | ||
result: result, | ||
message: 'Missing organization id', | ||
) | ||
end | ||
end | ||
end |