Skip to content
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

refactor: conditional routing #1728

Merged
merged 1 commit into from
Jan 9, 2024
Merged

Conversation

roschaefer
Copy link
Collaborator

@roschaefer roschaefer commented Nov 23, 2023

refactor: conditional routing

Motivation

It took me a while to debug the 404 error when clicking on the link to:

http://localhost:3000/onboarding/whats-app?jwt=eyJhbGc

I was expecting to see a problem in config/routes.rb but couldn't find anything. It was surprising to me that we programmatically throw a 404 in one of the controllers.

How to test

  1. bin/rspec ./spec/adapters/signal_adapter/api_spec.rb
  2. Tests pass

Requested changes

@mattwr18 asked me to implement this consistently across our codebase. I have seen this only once, here's the commit that introduced it: 9a541d6.
Thankfully there is already a test (that still fails if you remove conditional routing).

In the tests there was:

unless Setting.signal_server_phone_number
  allow(Setting).to receive(:signal_server_phone_number).and_return('SIGNAL_SERVER_PHONE_NUMBER')
  # ..
end

from 07694a6.

@mattwr18 this looks intentional, why was that? Did I miss anything?

@roschaefer roschaefer requested a review from mattwr18 November 23, 2023 17:34
roschaefer added a commit that referenced this pull request Nov 24, 2023
merge after #1728

Motivation
----------
So this is a follow up for #1728.

It will prevent rendering the whatsapp link unless activated.

We still have an inconsistency, because the channel links depend on
`Setting.channels` whereas the routing depends on
`Setting.whatsapp_configured?`. Ie. `Setting.channels` can be activated
for whatsapp although `Setting.whatsapp_configured?` is false.

How to test
-----------
1. `bin/rspec spec/system/onboarding/index.spec.rb`
2. See:
```
Onboarding
  visit /onboarding/
    if WhatsApp was explicitly activated or activated by configuration
      renders invitation link for WhatsApp
    but if WhatsApp is deactivated
      renders no invitation link for WhatsApp
```
@roschaefer roschaefer force-pushed the refactor-conditional-routing branch from a526c24 to 2fe370b Compare December 13, 2023 15:42
@@ -187,10 +182,8 @@
describe 'given a contributor who has unsubscribed and requests to resubscribe',
vcr: { cassette_name: :receive_signal_message_to_resubscribe } do
before do
unless Setting.signal_server_phone_number
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks intentional, why was this put in place? Did I miss sth. @mattwr18 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roschaefer we already had a conversation about this code in another PR; unfortunately, I can't find it. It was actually you that added this code in 5845dc4... You did not go into great detail why you added it, but the commit message states that you were fixing ci. It then has been refactored and copy/pasted throughout the spec file.

I can say for my part that I find the code useful the first time I record the cassette so that I can get some actual data back when I run the receive messages rake task. After the cassette is recorded, I think we can and probably should delete the code.

I think just having the line:

allow(Setting).to receive(:signal_server_phone_number).and_return('SIGNAL_SERVER_PHONE_NUMBER')

was enough to get the ci to pass 2 years ago, but I think you maybe wanted to continue using what you had configured in .env 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in our pairing, it's too confusing, so let's just remove it. Maybe we can check if we're in record mode instead of checking the configuration.

roschaefer added a commit that referenced this pull request Dec 13, 2023
merge after #1728

Motivation
----------
So this is a follow up for #1728.

It will prevent rendering the whatsapp link unless activated.

We still have an inconsistency, because the channel links depend on
`Setting.channels` whereas the routing depends on
`Setting.whatsapp_configured?`. Ie. `Setting.channels` can be activated
for whatsapp although `Setting.whatsapp_configured?` is false.

How to test
-----------
1. `bin/rspec spec/system/onboarding/index.spec.rb`
2. See:
```
Onboarding
  visit /onboarding/
    if WhatsApp was explicitly activated or activated by configuration
      renders invitation link for WhatsApp
    but if WhatsApp is deactivated
      renders no invitation link for WhatsApp
```
Copy link
Contributor

@mattwr18 mattwr18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good... thanks :)

@@ -187,10 +182,8 @@
describe 'given a contributor who has unsubscribed and requests to resubscribe',
vcr: { cassette_name: :receive_signal_message_to_resubscribe } do
before do
unless Setting.signal_server_phone_number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roschaefer we already had a conversation about this code in another PR; unfortunately, I can't find it. It was actually you that added this code in 5845dc4... You did not go into great detail why you added it, but the commit message states that you were fixing ci. It then has been refactored and copy/pasted throughout the spec file.

I can say for my part that I find the code useful the first time I record the cassette so that I can get some actual data back when I run the receive messages rake task. After the cassette is recorded, I think we can and probably should delete the code.

I think just having the line:

allow(Setting).to receive(:signal_server_phone_number).and_return('SIGNAL_SERVER_PHONE_NUMBER')

was enough to get the ci to pass 2 years ago, but I think you maybe wanted to continue using what you had configured in .env 🤷

Motivation
----------
It took me a while to debug the 404 error when clicking on the link to:
```
http://localhost:3000/onboarding/whats-app?jwt=eyJhbGc
```

I was expecting to see a problem in `config/routes.rb` but couldn't find anything. It was surprising to me that we programmatically throw a 404 in one of the controllers.

How to test
-----------
1. `bin/rspec ./spec/adapters/signal_adapter/api_spec.rb`
2. Tests pass

Requested changes
-----------------
@mattwr18 asked me to implement this consistently across our codebase. I have seen this only once, here's the commit that introduced it: 9a541d6.
Thankfully there is already a test (that still fails if you remove conditional routing).

In the tests there was:
```
unless Setting.signal_server_phone_number
  allow(Setting).to receive(:signal_server_phone_number).and_return('SIGNAL_SERVER_PHONE_NUMBER')
  # ..
end
```
from 07694a6.

@mattwr18 this looks intentional, why was that? Did I miss anything?
@roschaefer roschaefer force-pushed the refactor-conditional-routing branch from 2fe370b to b92128b Compare January 9, 2024 09:14
@roschaefer roschaefer enabled auto-merge January 9, 2024 09:22
@roschaefer roschaefer disabled auto-merge January 9, 2024 09:23
@roschaefer roschaefer enabled auto-merge January 9, 2024 09:23
@roschaefer roschaefer merged commit 4ea4001 into main Jan 9, 2024
1 check passed
@roschaefer roschaefer deleted the refactor-conditional-routing branch January 9, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants