RFC: migrate to cucumber

This commit is contained in:
Copple authored and egor-romanov committed 2022-04-08 16:34:15 +04:00
1 parent 316a2d1cf9
commit 834aa3c8c2
6 files changed
+64 -65

No files matched your search

-1
View File
@@ -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"
},
+13
View File
@@ -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
@@ -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'
})
+13
View File
@@ -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
-64
View File
@@ -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)
})
+13
View File
@@ -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"
}
}