Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
puria committed Feb 26, 2024
1 parent b90db3e commit 43e4a69
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 42 deletions.
10 changes: 5 additions & 5 deletions pkg/pocketbase/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const setupClient = p.new(['pb_address'], 'create pb_client', async (ctx)
if (!(await isPbRunning())) return ctx.fail('Client is not running');
return ctx.pass('pb client successfully created');
} catch (e) {
return ctx.fail('Invalid address');
throw new Error(e)
}
});

Expand All @@ -122,7 +122,7 @@ export const authWithPassword = p.new(['my_credentials'], 'login', async (ctx) =
.authWithPassword(credentials!.email, credentials!.password, { requestKey: null });
return ctx.pass({ token: res.token, record: res.record });
} catch (err) {
return ctx.fail(err);
throw new Error(err)
}
});

Expand Down Expand Up @@ -169,7 +169,7 @@ export const showRecord = p.new(['show_parameters'], 'ask record', async (ctx) =
const res = await pb.collection(p.collection).getOne(p.id, options);
return ctx.pass(res);
} catch (err) {
return ctx.fail(err);
throw new Error(err)
}
});

Expand All @@ -195,7 +195,7 @@ export const createRecord = p.new(
const res = await pb.collection(collection).create(record, options);
return ctx.pass(res);
} catch (err) {
return ctx.fail(err.message);
throw new Error(err.message);
}
},
);
Expand All @@ -222,7 +222,7 @@ export const updateRecord = p.new(
const res = await pb.collection(collection).update(id, record, options);
return ctx.pass(res);
} catch (err) {
return ctx.fail(err.message);
throw new Error(err.message);
}
},
);
Expand Down
23 changes: 11 additions & 12 deletions pkg/pocketbase/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import type {
import { pocketbase } from '@slangroom/pocketbase';
import test from 'ava';
import { Slangroom } from '@slangroom/core';
import 'dotenv/config';

const email = process.env['EMAIL']!;
const password = process.env['PASSWORD']!;
const pb_address = process.env['PB_ADDRESS']! as ServerUrl;
const email = "[email protected]";
const password = "testtest";
const pb_address = "http://127.0.0.1:8090/" as ServerUrl;

type DataCreate = {
create_parameters: CreateRecordParameters;
Expand Down Expand Up @@ -123,11 +122,11 @@ test('should retrieve paginated list of records', async (t) => {
data,
});
const output = res.result['output'] as {
records?: { items?: []; page?: number; perPage?: number };
records?: { items?: []; page?: string; perPage?: string};
};
t.truthy(Array.isArray(output.records?.items));
t.is(output.records?.page, 2);
t.is(output.records?.perPage, 20);
t.is(output.records?.page, '2');
t.is(output.records?.perPage, '20');
});

test('should retrieve first record that match filters', async (t) => {
Expand Down Expand Up @@ -172,7 +171,7 @@ test('should retrieve one record', async (t) => {
pb_address,
show_parameters: {
collection: 'organizations',
id: 'ouja6pwgxuyn2sd',
id: 'p7viyzsihrn52uj',
fields: 'name',
requestKey: null,
expand:null
Expand All @@ -199,14 +198,14 @@ test('should create a record', async (t) => {
`;
const slangroom = new Slangroom(pocketbase);


const data: DataCreate = {
pb_address,
create_parameters: {
collection: 'organizations',
record: {
name,
},
},
},
record_parameters: {
expand: null,
Expand All @@ -226,7 +225,7 @@ test('should create a record', async (t) => {
});

test('should update a record', async (t) => {


const scriptCreate = `
Rule unknown ignore
Expand Down Expand Up @@ -280,7 +279,7 @@ test('should update a record', async (t) => {

const outputCreate = createResult.result['output'] as { id: string, name: string}
const updatedName = `test-${randomString()}`

const dataUpdate: DataUpdate = {
pb_address,
update_parameters: {
Expand Down
Binary file added pkg/pocketbase/test/pb_data/data.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const collection = new Collection({
"id": "ffzsqtnsh1w2ayd",
"created": "2024-02-26 11:28:02.724Z",
"updated": "2024-02-26 11:28:02.724Z",
"name": "organizations",
"type": "base",
"system": false,
"schema": [
{
"system": false,
"id": "a9jbay3n",
"name": "name",
"type": "text",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": null,
"max": null,
"pattern": ""
}
},
{
"system": false,
"id": "z1xvmjl0",
"name": "owners",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "_pb_users_auth_",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
},
{
"system": false,
"id": "cy2pwsn3",
"name": "avatar",
"type": "file",
"required": false,
"presentable": false,
"unique": false,
"options": {
"mimeTypes": [],
"thumbs": [],
"maxSelect": 1,
"maxSize": 5242880,
"protected": false
}
},
{
"system": false,
"id": "u6ro0mgl",
"name": "description",
"type": "editor",
"required": false,
"presentable": false,
"unique": false,
"options": {
"convertUrls": false
}
}
],
"indexes": [],
"listRule": null,
"viewRule": null,
"createRule": null,
"updateRule": null,
"deleteRule": null,
"options": {}
});

return Dao(db).saveCollection(collection);
}, (db) => {
const dao = new Dao(db);
const collection = dao.findCollectionByNameOrId("ffzsqtnsh1w2ayd");

return dao.deleteCollection(collection);
})
Binary file added pkg/pocketbase/test/pocketbase
Binary file not shown.
57 changes: 32 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 43e4a69

Please sign in to comment.