Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Always update signup for latest (or empty) run, if it exists. #788

Merged
merged 6 commits into from
Dec 4, 2018

Conversation

DFurnes
Copy link
Contributor

@DFurnes DFurnes commented Dec 4, 2018

What's this PR do?

This pull request updates Rogue's POST v2/signups and POST v3/signups to always update the latest run if it exists for a campaign, rather than making a new one where the campaign_run_id is null. This will allow us to stop sending Campaign Run IDs (and run the script in #787) without breaking this functionality for applications that rely on it.

How should this be reviewed?

I added a failing test in 3e5590a which demonstrates the issue (we create a new signup when we shouldn't), and you can see the issue is fixed in e51a989. This doesn't break any other tests, and I don't believe we rely on the prior unexpected behavior anywhere.

Any background context you want to provide?

This was flagged by @weerd when testing Phoenix's new sans-runs signup logic.

Relevant tickets

Fixes #162426572.

How to deploy

https://github.com/DoSomething/rogue/blob/master/docs/development/deployments.md

@DFurnes DFurnes requested a review from a team as a code owner December 4, 2018 21:24
@@ -90,9 +90,6 @@ public function testNotCreatingDuplicateSignups()
{
$signup = factory(Signup::class)->states('contentful')->create();

// Mock the Blink API call.
$this->mock(Blink::class)->shouldReceive('userSignup');

$response = $this->withAccessToken($signup->northstar_id)->postJson('api/v3/signups', [
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious why you deleted here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not creating a signup, and so this method is never called. Mocking it is unnecessary, and potentially harmful since if we started sending userSignup events here due to a bug we'd never know it.

Copy link
Contributor

Choose a reason for hiding this comment

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

ohhh right because the signup already exists since we are creating it in the model factory - got it!

{
$signup = Signup::where([
'northstar_id' => $northstarId,
'campaign_id' => $campaignId,
'campaign_run_id' => $campaignRunId,
])->first();
])->orderByRaw('campaign_run_id IS NULL')
Copy link
Contributor

Choose a reason for hiding this comment

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

ah interesting! So orderByRaw just makes sure that the NULL values are at the bottom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! It should be the exact opposite, that was a mistake. Updated in c7deaa4.

The idea is that if we make new signups where campaign_run_id is null, we want those to be prioritized over old ones where this is a number. So the final query looks like kinda like this:

SELECT * FROM signups
WHERE northstar_id = "5543dfd6469c64ec7d8b46b3" AND campaign_id = 1144
ORDER BY campaign_run_id IS NULL DESC, `campaign_run_id` DESC LIMIT 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chloealee I added a new test for this in 9d794d2. Thanks for catching!

Copy link
Contributor

@chloealee chloealee left a comment

Choose a reason for hiding this comment

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

Looks great to me!!

@chloealee
Copy link
Contributor

Ah got it - thanks for explaining and putting in that extra test! I hadn't seen orderByRaw before so was trying to understand! Looks great !!

Copy link
Contributor

@chloealee chloealee left a comment

Choose a reason for hiding this comment

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

🎉

@@ -65,7 +65,7 @@ public function store(Request $request)
$northstarId = getNorthstarId($request);

// Check to see if the signup exists before creating one.
$signup = $this->signups->get($northstarId, $request['campaign_id'], $request['campaign_run_id']);
$signup = $this->signups->get($northstarId, $request['campaign_id']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, shoot. You’re totally right. We can revert this PR this morning to resolve that problem.

I think our best course of action is to avoid removing runs from applications until we’ve run the script in Rogue, since otherwise we don’t have a reliable way to know whether or not a signup is new. (Or we could adjust this to find the latest run for all signups on a given campaign ID, but I’m thinking that adds some unnecessary complexity and a chance we introduce other bugs.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ll update the order-of-operations issue to reflect this. cc: @chloealee @weerd

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants