Skip to content

Commit

Permalink
Merge pull request #205 from technologiestiftung/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
ff6347 authored May 23, 2023
2 parents a2c8c23 + f2d9add commit d7bea78
Show file tree
Hide file tree
Showing 69 changed files with 5,309 additions and 893 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@
"contributions": [
"doc"
]
},
{
"login": "dnsos",
"name": "Dennis Ostendorf",
"avatar_url": "https://avatars.githubusercontent.com/u/15640196?v=4",
"profile": "https://github.com/dnsos",
"contributions": [
"review"
]
},
{
"login": "julizet",
"name": "Julia Zet",
"avatar_url": "https://avatars.githubusercontent.com/u/52455010?v=4",
"profile": "https://github.com/julizet",
"contributions": [
"review"
]
}
],
"contributorsPerLine": 7
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- uses: supabase/setup-cli@v1
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
node-version-file: ".nvmrc"
- run: npm ci
- id: semantic-release
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@v3
with:
semantic_version: 18
env:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.13.0
18.16.0
8 changes: 6 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"recommendations": ["humao.rest-client", "mikestead.dotenv"]
}
"recommendations": [
"humao.rest-client",
"mikestead.dotenv",
"mkhl.direnv"
]
}
205 changes: 169 additions & 36 deletions README.md

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions __test-utils/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@ export async function truncateTreesAdopted() {
sql.end();
}

export async function createWateredTrees() {
export async function createWateredTrees(userId?: string, userName?: string) {
const sql = postgres(url);
const randomText = sql`md5(random()::text)`;
await sql`
INSERT INTO trees_watered (uuid, tree_id, amount, timestamp)
VALUES
('test', '_2100294b1f', 1, '2023-01-01 00:00:00'),
('test', '_2100294b1f', 1, '2023-01-01 00:00:00'),
('test', '_2100186c08', 1, '2023-01-01 00:00:00'),
('test', '_2100186c08', 1, '2023-01-01 00:00:00');
INSERT INTO trees_watered (uuid, amount, timestamp, username, tree_id)
SELECT
${userId ? userId : sql`extensions.uuid_generate_v4()::text`},
random() * 10,
NOW() - (random() * INTERVAL '7 days'),
${userName ? userName : randomText},
id
FROM
trees
ORDER BY
random()
LIMIT 10;
`;
sql.end();
}

export async function deleteSupabaseUser(email: string): Promise<void> {
const sql = postgres(url);
await sql`DELETE FROM auth.users WHERE email = ${email}`;
sql.end();
}
61 changes: 60 additions & 1 deletion __test-utils/req-test-token.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { SignupResponse } from "../_types/user";
import { SUPABASE_ANON_KEY, SUPABASE_URL } from "./supabase";
const issuer = process.env.issuer || "";
const client_id = process.env.client_id || "";
const client_secret = process.env.client_secret || "";
const audience = process.env.audience || "";

export async function requestTestToken() {
export async function requestAuth0TestToken() {
const response = await fetch(`${issuer}oauth/token`, {
method: "POST",
headers: {
Expand All @@ -23,3 +25,60 @@ export async function requestTestToken() {
const json = await response.json();
return json.access_token;
}

export async function requestSupabaseTestToken(
email: string,
password: string
) {
const response = await fetch(
`${SUPABASE_URL}/auth/v1/token?grant_type=password`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
apikey: SUPABASE_ANON_KEY,
},
body: JSON.stringify({
email,
password,
}),
}
);
if (!response.ok) {
const json = await response.text();
throw new Error(`Could not get test token, ${json}`);
}
const json = (await response.json()) as SignupResponse;
return json.access_token;
}

export async function createSupabaseUser(
email: string,
password: string,
opts?: { returnFullUser: boolean }
) {
const response = await fetch(`${SUPABASE_URL}/auth/v1/signup`, {
method: "POST",
headers: {
"Content-Type": "application/json",
apikey: SUPABASE_ANON_KEY,
},
body: JSON.stringify({
email,
password,
}),
});
if (!response.ok) {
console.log(response.status);
const json = await response.text();
throw new Error(`Could not create test user, ${json}`);
}
const json = (await response.json()) as {
access_token: string;
user: { id: string };
};
if (opts?.returnFullUser) {
return json;
}
return json.access_token;
}
16 changes: 16 additions & 0 deletions __test-utils/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createClient } from "@supabase/supabase-js";
import { Database } from "../_types/database";
export const SUPABASE_URL =
process.env.SUPABASE_URL || "http://localhost:54321";
export const SUPABASE_ANON_KEY = process.env.SUPABASE_ANON_KEY || "";
export const SUPABASE_SERVICE_ROLE_KEY =
process.env.SUPABASE_SERVICE_ROLE_KEY || "";

export const supabaseAnonClient = createClient<Database>(
SUPABASE_URL,
SUPABASE_ANON_KEY
);
export const supabaseServiceRoleClient = createClient<Database>(
SUPABASE_URL,
SUPABASE_SERVICE_ROLE_KEY
);
Loading

1 comment on commit d7bea78

@vercel
Copy link

@vercel vercel bot commented on d7bea78 May 23, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.