-
Notifications
You must be signed in to change notification settings - Fork 33
Add permissions to Role
#382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+202
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,142 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| describe WorkOS::Role do | ||
| describe '.initialize' do | ||
| context 'with full role data including permissions' do | ||
| it 'initializes all attributes correctly' do | ||
| role_json = { | ||
| id: 'role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY', | ||
| name: 'Admin', | ||
| slug: 'admin', | ||
| description: 'Administrator role with full access', | ||
| permissions: ['read:users', 'write:users', 'admin:all'], | ||
| type: 'system', | ||
| created_at: '2022-05-13T17:45:31.732Z', | ||
| updated_at: '2022-07-13T17:45:42.618Z', | ||
| }.to_json | ||
|
|
||
| role = described_class.new(role_json) | ||
|
|
||
| expect(role.id).to eq('role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY') | ||
| expect(role.name).to eq('Admin') | ||
| expect(role.slug).to eq('admin') | ||
| expect(role.description).to eq('Administrator role with full access') | ||
| expect(role.permissions).to eq(['read:users', 'write:users', 'admin:all']) | ||
| expect(role.type).to eq('system') | ||
| expect(role.created_at).to eq('2022-05-13T17:45:31.732Z') | ||
| expect(role.updated_at).to eq('2022-07-13T17:45:42.618Z') | ||
| end | ||
| end | ||
|
|
||
| context 'with role data without permissions' do | ||
| it 'initializes permissions as empty array' do | ||
| role_json = { | ||
| id: 'role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY', | ||
| name: 'User', | ||
| slug: 'user', | ||
| description: 'Basic user role', | ||
| type: 'custom', | ||
| created_at: '2022-05-13T17:45:31.732Z', | ||
| updated_at: '2022-07-13T17:45:42.618Z', | ||
| }.to_json | ||
|
|
||
| role = described_class.new(role_json) | ||
|
|
||
| expect(role.id).to eq('role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY') | ||
| expect(role.name).to eq('User') | ||
| expect(role.slug).to eq('user') | ||
| expect(role.description).to eq('Basic user role') | ||
| expect(role.permissions).to eq([]) | ||
| expect(role.type).to eq('custom') | ||
| expect(role.created_at).to eq('2022-05-13T17:45:31.732Z') | ||
| expect(role.updated_at).to eq('2022-07-13T17:45:42.618Z') | ||
| end | ||
| end | ||
|
|
||
| context 'with role data with null permissions' do | ||
| it 'initializes permissions as empty array' do | ||
| role_json = { | ||
| id: 'role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY', | ||
| name: 'User', | ||
| slug: 'user', | ||
| description: 'Basic user role', | ||
| permissions: nil, | ||
| type: 'custom', | ||
| created_at: '2022-05-13T17:45:31.732Z', | ||
| updated_at: '2022-07-13T17:45:42.618Z', | ||
| }.to_json | ||
|
|
||
| role = described_class.new(role_json) | ||
|
|
||
| expect(role.permissions).to eq([]) | ||
| end | ||
| end | ||
|
|
||
| context 'with role data with empty permissions array' do | ||
| it 'preserves empty permissions array' do | ||
| role_json = { | ||
| id: 'role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY', | ||
| name: 'User', | ||
| slug: 'user', | ||
| description: 'Basic user role', | ||
| permissions: [], | ||
| type: 'custom', | ||
| created_at: '2022-05-13T17:45:31.732Z', | ||
| updated_at: '2022-07-13T17:45:42.618Z', | ||
| }.to_json | ||
|
|
||
| role = described_class.new(role_json) | ||
|
|
||
| expect(role.permissions).to eq([]) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '.to_json' do | ||
| context 'with role that has permissions' do | ||
| it 'includes permissions in serialized output' do | ||
| role_json = { | ||
| id: 'role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY', | ||
| name: 'Admin', | ||
| slug: 'admin', | ||
| description: 'Administrator role', | ||
| permissions: ['read:all', 'write:all'], | ||
| type: 'system', | ||
| created_at: '2022-05-13T17:45:31.732Z', | ||
| updated_at: '2022-07-13T17:45:42.618Z', | ||
| }.to_json | ||
|
|
||
| role = described_class.new(role_json) | ||
| serialized = role.to_json | ||
|
|
||
| expect(serialized[:id]).to eq('role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY') | ||
| expect(serialized[:name]).to eq('Admin') | ||
| expect(serialized[:slug]).to eq('admin') | ||
| expect(serialized[:description]).to eq('Administrator role') | ||
| expect(serialized[:permissions]).to eq(['read:all', 'write:all']) | ||
| expect(serialized[:type]).to eq('system') | ||
| expect(serialized[:created_at]).to eq('2022-05-13T17:45:31.732Z') | ||
| expect(serialized[:updated_at]).to eq('2022-07-13T17:45:42.618Z') | ||
| end | ||
| end | ||
|
|
||
| context 'with role that has no permissions' do | ||
| it 'includes empty permissions array in serialized output' do | ||
| role_json = { | ||
| id: 'role_01FAEAJCJ3P1Z6WP5Y9VQPN2XY', | ||
| name: 'User', | ||
| slug: 'user', | ||
| description: 'Basic user role', | ||
| type: 'custom', | ||
| created_at: '2022-05-13T17:45:31.732Z', | ||
| updated_at: '2022-07-13T17:45:42.618Z', | ||
| }.to_json | ||
|
|
||
| role = described_class.new(role_json) | ||
| serialized = role.to_json | ||
|
|
||
| expect(serialized[:permissions]).to eq([]) | ||
| end | ||
| end | ||
| end | ||
| end |
14 changes: 7 additions & 7 deletions
14
spec/support/fixtures/vcr_cassettes/organization/list_organization_roles.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic:
.to_jsonreturns a JSON string, but test expects a hash. Should be testing againstbilling_role.as_jsonor parsing the JSON string firstThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_jsonreturns a hash. We do things a little different around here. 🤠