diff --git a/src/lib/PostgrestTransformBuilder.ts b/src/lib/PostgrestTransformBuilder.ts index 92d9eaf8..ca2ab2a9 100644 --- a/src/lib/PostgrestTransformBuilder.ts +++ b/src/lib/PostgrestTransformBuilder.ts @@ -123,8 +123,8 @@ export default class PostgrestTransformBuilder extends PostgrestBuilder { /** * Set the response type to CSV. */ - csv(): this { + csv(): PromiseLike> { this.headers['Accept'] = 'text/csv' - return this + return this as PromiseLike> } } diff --git a/src/lib/types.ts b/src/lib/types.ts index a83707d3..67d124a7 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -104,8 +104,13 @@ export abstract class PostgrestBuilder implements PromiseLike { }) test('connection error', async () => { - const postgrest = new PostgrestClient('http://this.url.does.not.exist') + const postgrest = new PostgrestClient('http://foo.invalid') let isErrorCaught = false await postgrest .from('user') @@ -121,14 +121,13 @@ test('connection error', async () => { }) test('connection errors should work the same with throwOnError', async () => { - const postgrest = new PostgrestClient('http://this.url.does.not.exist') + const postgrest = new PostgrestClient('http://foo.invalid') let isErrorCaught = false await postgrest .from('user') .select() .throwOnError() - .then(undefined, (error) => { - expect(error).toMatchSnapshot() + .then(undefined, () => { isErrorCaught = true }) expect(isErrorCaught).toBe(true) diff --git a/test/transforms.ts b/test/transforms.ts index af0bf457..b4b6afea 100644 --- a/test/transforms.ts +++ b/test/transforms.ts @@ -56,3 +56,25 @@ test('select on stored procedure', async () => { .select('status') expect(res).toMatchSnapshot() }) + +test('csv', async () => { + const res = await postgrest.from('users').select().csv() + expect(res).toMatchInlineSnapshot(` + Object { + "body": "username,data,age_range,status,catchphrase + supabot,,\\"[1,2)\\",ONLINE,\\"'cat' 'fat'\\" + kiwicopple,,\\"[25,35)\\",OFFLINE,\\"'bat' 'cat'\\" + awailas,,\\"[25,35)\\",ONLINE,\\"'bat' 'rat'\\" + dragarcia,,\\"[20,30)\\",ONLINE,\\"'fat' 'rat'\\"", + "count": null, + "data": "username,data,age_range,status,catchphrase + supabot,,\\"[1,2)\\",ONLINE,\\"'cat' 'fat'\\" + kiwicopple,,\\"[25,35)\\",OFFLINE,\\"'bat' 'cat'\\" + awailas,,\\"[25,35)\\",ONLINE,\\"'bat' 'rat'\\" + dragarcia,,\\"[20,30)\\",ONLINE,\\"'fat' 'rat'\\"", + "error": null, + "status": 200, + "statusText": "OK", + } + `) +})