Skip to content

Commit d29048f

Browse files
committed
test: update
1 parent 134a58d commit d29048f

File tree

6 files changed

+197
-212
lines changed

6 files changed

+197
-212
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"build:module": "tsc -p tsconfig.module.json",
2626
"test": "run-s db:clean db:run && jest --runInBand; run-s db:clean",
2727
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot; run-s db:clean",
28-
"db:clean": "cd test/db && docker-compose down",
28+
"db:clean": "cd test/db && docker-compose down --volumes",
2929
"db:run": "cd test/db && docker-compose up --detach && wait-for-localhost 3000",
3030
"docs": "typedoc src/index.ts",
3131
"docs:json": "typedoc --json docs/spec.json src/index.ts"

test/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ Object {
11861186
exports[`rpc returns void 1`] = `
11871187
Object {
11881188
"count": undefined,
1189-
"data": null,
1189+
"data": undefined,
11901190
"error": undefined,
11911191
"status": 204,
11921192
"statusText": "No Content",

test/db/00-schema.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ CREATE FUNCTION public.void_func()
5151
RETURNS void AS $$
5252
$$ LANGUAGE SQL;
5353

54-
create extension postgis;
54+
create schema extensions;
55+
create extension postgis schema extensions;
5556

5657
create table public.shops (
5758
id int primary key
5859
, address text
59-
, shop_geom geometry(POINT, 4326)
60+
, shop_geom extensions.geometry(POINT, 4326)
6061
);
6162

6263
-- SECOND SCHEMA USERS

test/db/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ services:
99
environment:
1010
PGRST_DB_URI: postgres://postgres:postgres@db:5432/postgres
1111
PGRST_DB_SCHEMAS: public,personal
12+
PGRST_DB_EXTRA_SEARCH_PATH: extensions
1213
PGRST_DB_ANON_ROLE: postgres
1314
PGRST_DB_PLAN_ENABLED: 1
1415
depends_on:
1516
- db
1617
db:
17-
image: postgis/postgis:12-3.2
18+
image: supabase/postgres:14.1.0.34
1819
ports:
1920
- '5432:5432'
2021
volumes:

test/transforms.ts

Lines changed: 90 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -97,123 +97,109 @@ test('abort signal', async () => {
9797
`)
9898
})
9999

100-
test('geojson', async () => {
101-
const res = await postgrest
102-
.from('shops')
103-
.select()
104-
.geojson()
105-
.then((res) => res.data)
100+
// test('geojson', async () => {
101+
// const res = await postgrest.from('shops').select().geojson()
102+
// expect(res).toMatchInlineSnapshot()
103+
// })
104+
105+
test('explain', async () => {
106+
const res = await postgrest.from('users').select().explain()
106107
expect(res).toMatchInlineSnapshot(`
107108
Object {
108-
"features": Array [
109+
"count": undefined,
110+
"data": Array [
109111
Object {
110-
"geometry": Object {
111-
"coordinates": Array [
112-
-71.10044,
113-
42.373695,
112+
"Plan": Object {
113+
"Async Capable": false,
114+
"Node Type": "Aggregate",
115+
"Parallel Aware": false,
116+
"Partial Mode": "Simple",
117+
"Plan Rows": 1,
118+
"Plan Width": 112,
119+
"Plans": Array [
120+
Object {
121+
"Alias": "users",
122+
"Async Capable": false,
123+
"Node Type": "Seq Scan",
124+
"Parallel Aware": false,
125+
"Parent Relationship": "Outer",
126+
"Plan Rows": 510,
127+
"Plan Width": 132,
128+
"Relation Name": "users",
129+
"Startup Cost": 0,
130+
"Total Cost": 15.1,
131+
},
114132
],
115-
"type": "Point",
133+
"Startup Cost": 17.65,
134+
"Strategy": "Plain",
135+
"Total Cost": 17.68,
116136
},
117-
"properties": Object {
118-
"address": "1369 Cambridge St",
119-
"id": 1,
120-
},
121-
"type": "Feature",
122137
},
123138
],
124-
"type": "FeatureCollection",
139+
"error": undefined,
140+
"status": 200,
141+
"statusText": "OK",
125142
}
126143
`)
127144
})
128145

129-
test('explain', async () => {
130-
const res = await postgrest
131-
.from('users')
132-
.select()
133-
.explain()
134-
.then((res) => res.data)
135-
expect(res).toMatchInlineSnapshot(`
136-
Array [
137-
Object {
138-
"Plan": Object {
139-
"Node Type": "Aggregate",
140-
"Parallel Aware": false,
141-
"Partial Mode": "Simple",
142-
"Plan Rows": 1,
143-
"Plan Width": 112,
144-
"Plans": Array [
145-
Object {
146-
"Alias": "users",
147-
"Node Type": "Seq Scan",
148-
"Parallel Aware": false,
149-
"Parent Relationship": "Outer",
150-
"Plan Rows": 510,
151-
"Plan Width": 132,
152-
"Relation Name": "users",
153-
"Startup Cost": 0,
154-
"Total Cost": 15.1,
155-
},
156-
],
157-
"Startup Cost": 17.65,
158-
"Strategy": "Plain",
159-
"Total Cost": 17.68,
160-
},
161-
},
162-
]
163-
`)
164-
})
165-
166146
test('explain with options', async () => {
167-
const res = await postgrest
168-
.from('users')
169-
.select()
170-
.explain({ verbose: true, settings: true })
171-
.then((res) => res.data)
147+
const res = await postgrest.from('users').select().explain({ verbose: true, settings: true })
172148
expect(res).toMatchInlineSnapshot(`
173-
Array [
174-
Object {
175-
"Plan": Object {
176-
"Node Type": "Aggregate",
177-
"Output": Array [
178-
"NULL::bigint",
179-
"count(ROW(users.username, users.data, users.age_range, users.status, users.catchphrase))",
180-
"(COALESCE(json_agg(ROW(users.username, users.data, users.age_range, users.status, users.catchphrase)), '[]'::json))::character varying",
181-
"NULLIF(current_setting('response.headers'::text, true), ''::text)",
182-
"NULLIF(current_setting('response.status'::text, true), ''::text)",
183-
],
184-
"Parallel Aware": false,
185-
"Partial Mode": "Simple",
186-
"Plan Rows": 1,
187-
"Plan Width": 112,
188-
"Plans": Array [
189-
Object {
190-
"Alias": "users",
191-
"Node Type": "Seq Scan",
192-
"Output": Array [
193-
"users.username",
194-
"users.data",
195-
"users.age_range",
196-
"users.status",
197-
"users.catchphrase",
198-
],
199-
"Parallel Aware": false,
200-
"Parent Relationship": "Outer",
201-
"Plan Rows": 510,
202-
"Plan Width": 132,
203-
"Relation Name": "users",
204-
"Schema": "public",
205-
"Startup Cost": 0,
206-
"Total Cost": 15.1,
207-
},
208-
],
209-
"Startup Cost": 17.65,
210-
"Strategy": "Plain",
211-
"Total Cost": 17.68,
212-
},
213-
"Settings": Object {
214-
"search_path": "\\\"public\\\", \\\"public\\\"",
149+
Object {
150+
"count": undefined,
151+
"data": Array [
152+
Object {
153+
"Plan": Object {
154+
"Async Capable": false,
155+
"Node Type": "Aggregate",
156+
"Output": Array [
157+
"NULL::bigint",
158+
"count(ROW(users.username, users.data, users.age_range, users.status, users.catchphrase))",
159+
"(COALESCE(json_agg(ROW(users.username, users.data, users.age_range, users.status, users.catchphrase)), '[]'::json))::character varying",
160+
"NULLIF(current_setting('response.headers'::text, true), ''::text)",
161+
"NULLIF(current_setting('response.status'::text, true), ''::text)",
162+
],
163+
"Parallel Aware": false,
164+
"Partial Mode": "Simple",
165+
"Plan Rows": 1,
166+
"Plan Width": 112,
167+
"Plans": Array [
168+
Object {
169+
"Alias": "users",
170+
"Async Capable": false,
171+
"Node Type": "Seq Scan",
172+
"Output": Array [
173+
"users.username",
174+
"users.data",
175+
"users.age_range",
176+
"users.status",
177+
"users.catchphrase",
178+
],
179+
"Parallel Aware": false,
180+
"Parent Relationship": "Outer",
181+
"Plan Rows": 510,
182+
"Plan Width": 132,
183+
"Relation Name": "users",
184+
"Schema": "public",
185+
"Startup Cost": 0,
186+
"Total Cost": 15.1,
187+
},
188+
],
189+
"Startup Cost": 17.65,
190+
"Strategy": "Plain",
191+
"Total Cost": 17.68,
192+
},
193+
"Query Identifier": -8888327821402777000,
194+
"Settings": Object {
195+
"effective_cache_size": "128MB",
196+
"search_path": "\\"public\\", \\"extensions\\"",
197+
},
215198
},
216-
},
217-
]
199+
],
200+
"error": undefined,
201+
"status": 200,
202+
"statusText": "OK",
203+
}
218204
`)
219205
})

0 commit comments

Comments
 (0)