Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

RFC: migrate to cucumber

Copple834aa3c8c216
diff --git a/package.json b/package.json
index e7dd8e94d8c..409208e3809 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,6 @@
"docker:up": "cd docker && docker-compose up",
"docker:down": "cd docker && docker-compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml down --remove-orphans",
"docker:remove": "cd docker && docker-compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml rm -vfs",
- "test": "jest",
"perf:kong": "ab -t 5 -c 20 -T application/json http://localhost:8000/",
"perf:meta": "ab -t 5 -c 20 -T application/json http://localhost:5555/tables"
},
diff --git a/tests/features/authentication.feature b/tests/features/authentication.feature
new file mode 100644
index 00000000000..5f7500a7f9e
--- /dev/null
+++ b/tests/features/authentication.feature
@@ -0,0 +1,13 @@
+Feature: User Authentication
+
+ Scenario: New users
+ Given an anonymous user
+ When I sign up with a valid email and password
+ Then I should be logged in
+ And I should be able to log out
+
+ Scenario: Existing users
+ Given an existing user
+ When I sign up with a valid email and password
+ Then I should be logged in
+ And I should be able to log out
diff --git a/tests/features/javascript/authentication.js b/tests/features/javascript/authentication.js
new file mode 100644
index 00000000000..a0849d3f947
--- /dev/null
+++ b/tests/features/javascript/authentication.js
@@ -0,0 +1,25 @@
+const { Given, Then, When } = require('cucumber')
+
+Given('an anonymous user', function () {
+ // Write code here that turns the phrase above into concrete actions
+ return 'pending'
+})
+
+Given('an existing user', function () {
+ // Write code here that turns the phrase above into concrete actions
+ return 'pending'
+})
+
+When('I sign up with a valid email and password', function () {
+ // Write code here that turns the phrase above into concrete actions
+ return 'pending'
+})
+Then('I should be logged in', function () {
+ // Write code here that turns the phrase above into concrete actions
+ return 'pending'
+})
+
+Then('I should be able to log out', function () {
+ // Write code here that turns the phrase above into concrete actions
+ return 'pending'
+})
diff --git a/tests/features/python/authentication.py b/tests/features/python/authentication.py
new file mode 100644
index 00000000000..f78c4626e65
--- /dev/null
+++ b/tests/features/python/authentication.py
@@ -0,0 +1,13 @@
+from behave import *
+
+@given('an anonymous user')
+def step_impl(context):
+ pass
+
+@when('an existing user')
+def step_impl(context):
+ assert True is not False
+
+@then('I sign up with a valid email and password')
+def step_impl(context):
+ assert context.failed is False
diff --git a/tests/integration/index.test.ts b/tests/integration/index.test.ts
deleted file mode 100644
index da73c510452..00000000000
--- a/tests/integration/index.test.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import * as faker from 'faker'
-import { createClient } from '@supabase/supabase-js'
-
-const unauthorized = createClient(process.env.SUPABASE_URL, 'FAKE_KEY')
-const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY_ANON)
-const admin = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY_ADMIN)
-
-test('Unauthorized', async () => {
- const { error } = await unauthorized.from('profiles').select()
- expect(error.message).toBe('Invalid authentication credentials')
-})
-
-test('Simple test', async () => {
- const fakeOne = {
- email: faker.internet.email().toLowerCase(),
- password: faker.internet.password(),
- username: faker.internet.userName(),
- }
- const fakeTwo = {
- email: faker.internet.email().toLowerCase(),
- password: faker.internet.password(),
- username: faker.internet.userName(),
- }
- const first = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY_ANON)
- const second = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY_ANON)
-
- const { user: firstUser } = await first.auth.signUp({
- email: fakeOne.email,
- password: fakeOne.password,
- })
- const { user: secondUser } = await second.auth.signUp({
- email: fakeTwo.email,
- password: fakeTwo.password,
- })
- expect(firstUser.email).toEqual(fakeOne.email)
- expect(secondUser.email).toEqual(fakeTwo.email)
-
- const { data: firstProfile } = await first
- .from('profiles')
- .insert({
- id: firstUser.id,
- username: fakeOne.username,
- })
- .single()
- expect(firstProfile.username).toMatch(fakeOne.username)
-
- // Cannot insert the second user on the first client
- const { error: secondProfile } = await first
- .from('profiles')
- .insert({
- id: secondUser.id,
- username: fakeTwo.username,
- })
- .single()
- expect(secondProfile.message).toMatch(/new row violates row-level security policy for table/)
-
- const { data: firstProfileList } = await first.from('profiles').select()
- const { data: secondProfileList } = await second.from('profiles').select()
- const { data: adminProfileList } = await admin.from('profiles').select()
-
- expect(firstProfileList.length).toBe(1)
- expect(secondProfileList.length).toBe(0)
- expect(adminProfileList.length).toBeGreaterThanOrEqual(1)
-})
diff --git a/tests/package.json b/tests/package.json
new file mode 100644
index 00000000000..03a057d7a35
--- /dev/null
+++ b/tests/package.json
@@ -0,0 +1,13 @@
+{
+ "name": "supabase-tests",
+ "version": "1.0.0",
+ "description": "These tests can be run with Docker.",
+ "scripts": {
+ "test:js": "node ./node_modules/.bin/cucumber-js tests/ -r tests/features/definitions"
+ },
+ "author": "Supabase, Inc.",
+ "license": "MIT",
+ "devDependencies": {
+ "cucumber": "^7.0.0-rc.0"
+ }
+}