Skip to content

Commit dcb5abe

Browse files
committed
refactor: tests. Allows them to connect to a supabase instance rather than a docker container
1 parent eb14a28 commit dcb5abe

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
supabase:
55
image: supabase/supabase-dev:0.1.9
66
ports:
7-
- "8000:8000"
7+
- "1234:8000"
88
environment:
99
DB_HOST: db
1010
DB_NAME: postgres
@@ -16,8 +16,8 @@ services:
1616
- db
1717
db:
1818
image: postgres:12
19-
ports:
20-
- "6543:5432"
19+
# ports:
20+
# - "6543:5432"
2121
volumes:
2222
- ./test/db:/docker-entrypoint-initdb.d/
2323
command:

test/integration/testAuth.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
1+
require('dotenv').config()
2+
import { createClient } from '../../src'
13
const chai = require('chai')
24
const expect = chai.expect
35
const assert = chai.assert
46
chai.use(require('chai-as-promised'))
57

6-
import { createClient } from '../../src'
8+
const SUPABASE_URL = process.env.SUPABASE_URL || 'http://localhost:1234'
9+
const SUPABASE_KEY = process.env.SUPABASE_KEY || 'examplekey'
10+
11+
console.log('SUPABASE_KEY', SUPABASE_KEY)
712

813
describe('test signing up and logging in as a new user', () => {
914
const supabase = createClient(
10-
'https://HPPNcyqrPOIDwqzQHjRl.supabase.net',
11-
'JBkDpEMQw9a9yIeVuFhTt5JEhGjQEY'
15+
'https://nuaqAUDnliweFqRoinst.supabase.net',
16+
'ucHLLNUUFXVn2o6pRCcQOW82KF0RAs'
1217
)
1318
const randomEmail = `a${Math.random()}@google.com`
1419

1520
it('should register a new user', async () => {
16-
const response = await supabase.auth.signup(randomEmail, '11password')
17-
assert(response.email === randomEmail, 'user could not sign up')
21+
try {
22+
const response = await supabase.auth.signup(randomEmail, '11password')
23+
console.log('response', response)
24+
const {body:countries} = await supabase.from('countries').select('*').limit(1)
25+
console.log('countries', countries)
26+
assert(response.email === randomEmail, 'user could not sign up')
27+
} catch (error) {
28+
// console.log('error', error)
29+
assert(!error, 'sign up returns an error')
30+
}
1831
})
1932

2033
it('should log in a user and return an access token', async () => {
21-
const response = await supabase.auth.login(randomEmail, '11password')
22-
assert(response.body.access_token !== undefined, 'user could not log in')
34+
try {
35+
const response = await supabase.auth.login(randomEmail, '11password')
36+
assert(response.body.access_token !== undefined, 'user could not log in')
37+
} catch (error) {
38+
// console.log('error', error)
39+
assert(!error, 'log in returns an error')
40+
}
2341
})
2442

2543
it('should return the currently logged in user', async () => {
26-
const user = await supabase.auth.user()
27-
assert(user.email === randomEmail, 'user could not be retrieved')
44+
try {
45+
const user = await supabase.auth.user()
46+
assert(user.email === randomEmail, 'user could not be retrieved')
47+
} catch (error) {
48+
// console.log('error', error)
49+
assert(!error, 'logged in user returns an error')
50+
}
2851
})
2952

3053
it('should logout and invalidate the previous access_token', async () => {

test/integration/testFilters.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
require('dotenv').config()
12
import { assert } from 'chai'
23
import { createClient } from '../../src'
34

5+
const SUPABASE_URL = process.env.SUPABASE_URL || 'http://localhost:1234'
6+
const SUPABASE_KEY = process.env.SUPABASE_KEY || 'examplekey'
7+
48
describe('test reading from the rest interface', () => {
5-
const supabase = createClient('http://localhost:8000', 'examplekey')
9+
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
10+
611
const expectedQueryArray = [
712
'name=eq.New Zealand',
813
'id=gt.20',

test/integration/testRealtime.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
require('dotenv').config()
12
import { assert } from 'chai'
23
import { createClient } from '../../src'
34

5+
const SUPABASE_URL = process.env.SUPABASE_URL || 'http://localhost:1234'
6+
const SUPABASE_KEY = process.env.SUPABASE_KEY || 'examplekey'
7+
48
describe('test various subscriptions', function() {
5-
const supabase = createClient('http://localhost:8000', 'examplekey')
9+
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
610

711
afterEach(function() {
812
const subscriptions = supabase.getSubscriptions()

test/integration/testRest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
require('dotenv').config()
12
import { assert } from 'chai'
23
import { createClient } from '../../src'
34

5+
const SUPABASE_URL = process.env.SUPABASE_URL || 'http://localhost:1234'
6+
const SUPABASE_KEY = process.env.SUPABASE_KEY || 'examplekey'
7+
48
describe('test reading from the rest interface', () => {
5-
const supabase = createClient('http://localhost:8000', 'examplekey')
9+
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
610

711
it('from() and select()', async () => {
812
const response = await supabase

0 commit comments

Comments
 (0)