-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add missing redirects and Cypress tests for them
- Loading branch information
1 parent
1df8b47
commit 7d466d5
Showing
15 changed files
with
179 additions
and
30 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
import cookie from 'cookie' | ||
|
||
export function hasDecisionBeenSeen(request, social) { | ||
const cookieHeader = request.headers.get('cookie') | ||
const cookies = cookie.parse(cookieHeader || '') | ||
return social.decision !== cookies.decision | ||
} | ||
|
||
export function decisionRedirect(socialId) { | ||
return { | ||
status: 303, | ||
headers: { | ||
location: `/${socialId}/decision`, | ||
}, | ||
} | ||
} |
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,34 @@ | ||
import faunadb from 'faunadb' | ||
import {toDatabaseId} from '$lib/id' | ||
import convertDatesToStrings from '$lib/convertDatesToStrings' | ||
import {decisionRedirect, hasDecisionBeenSeen} from '$lib/redirectToDecision' | ||
|
||
const q = faunadb.query | ||
|
||
const client = new faunadb.Client({ | ||
domain: process.env.FAUNADB_DOMAIN, | ||
port: process.env.FAUNADB_PORT, | ||
scheme: process.env.FAUNADB_SCHEME, | ||
secret: process.env.FAUNADB_SERVER_SECRET, | ||
}) | ||
|
||
export async function get({params, locals, request}) { | ||
const socialId = params.socialId | ||
const reference = toDatabaseId(socialId) | ||
const response = await client.query( | ||
q.Get(q.Ref(q.Collection('social'), reference)), | ||
) | ||
const social = convertDatesToStrings(response.data) | ||
if (social.decision) social.decision = social.decision.value | ||
const user = social.invitees[locals.userId] | ||
|
||
if (hasDecisionBeenSeen(request, social)) return decisionRedirect(socialId) | ||
|
||
return { | ||
status: 200, | ||
body: { | ||
social, | ||
user, | ||
}, | ||
} | ||
} |
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