-
Notifications
You must be signed in to change notification settings - Fork 3
myriam #2
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
base: main
Are you sure you want to change the base?
myriam #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,24 @@ | |
|
|
||
| RSpec.describe 'Result for API' do | ||
| def result_for_api(status, api) | ||
| # TODO | ||
| success = api.is_a?(Hash) ? api[:success] : nil | ||
|
|
||
| case [status, api, success] | ||
| in [200, {}, nil] | ||
| Result::Success.new(nil) | ||
| in [200, Hash, false] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vu que c'est le seul cas ou tu vérifies vraiment
|
||
| Result::Failure.new([]) | ||
| in [200, Hash, nil] | ||
| Result::Success.new(api[:payload] || api.except(:success)) | ||
| in [200, Hash, true] | ||
| Result::Success.new(api[:payload] || api.except(:success)) | ||
|
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Du coup, vu que tu as deux fois le même bloc et pas d'assignation de variables, tu peux dé-dupliquer avec Tu peux aussi pousser le matching pour te débarasser de in [200, { success:, payload:, **nil }]
Result::Success.new(payload)
in [200, { success:, **payload }]
Result::Success.new(payload)
in [200, { payload:, **nil }]
Result::Success.new(payload)
in [200, { **payload }]
Result::Success.new(payload)Après c'est pousser ça au maximum. |
||
| in [500, {}, nil] | ||
| Result::Failure.new([]) | ||
| in [500, String, nil] | ||
| Result::Failure.new([api]) | ||
| in [500, Hash, nil] | ||
| Result::Failure.new(api.values.flatten) | ||
| end | ||
| end | ||
|
|
||
| context 'status OK' do | ||
|
|
||
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.
Je pense en vrai que tu pourrais défaulter sur
trueet complètement ignorer le casnilL'exercise était pensé pour que
result_for_apine soit que un simplecase in, mais si on se permet effectivement cette assignation avant, on pourrait aussi directement prendre en compte le status dans la même étape, ce qui donnerait:(Même si à nouveau, ca autoriserait a avoir un status 500 qui a un
success: true, mais bon, en dehors des cas d'exemple).Du coup, ton
case inse simplifie pas mal.