-
-
Notifications
You must be signed in to change notification settings - Fork 84
Client (on server) tests for example interface #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leonpolak
wants to merge
16
commits into
master
Choose a base branch
from
client-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3399aaa
Initial tests for server side Client
leonpolak d0cfb5e
Tests for most of the example rpc calls
leonpolak b1ff004
Tests for example interface
leonpolak e1220f5
Initial tests for server side Client
leonpolak f1e5d4d
Tests for most of the example rpc calls
leonpolak f866e65
Tests for example interface
leonpolak 924bbc9
Apply suggestions from code review
tshemsedinov 6138196
Subscription and redis tests
tshemsedinov 149e0ae
Apply prettier
tshemsedinov d41efdd
Fix linter
tshemsedinov 5118524
Run client test
tshemsedinov 64c06d2
Merge branch 'client-tests' of https://github.com/metarhia/Example in…
leonpolak b8d4b8f
Trying to force tests to work as planned. Unsuccessfully.
leonpolak 811643d
Synchronizing package.json with master
leonpolak 6d771f9
Merge branch 'master' into client-tests
leonpolak 1773d81
Cnanging the test to use the new metacom/lib/client.js
leonpolak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ({ | ||
| router({ method, args, verb, headers }) { | ||
| const ip = context.client.ip; | ||
| console.log({ method, args, ip, verb, headers }); | ||
| return {success:true, method, args, ip, verb, headers }; | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| 'use strict'; | ||
|
|
||
| const runTests = (wsClient, wsToken, httpClient, httpToken) => { | ||
| const metatests = require('metatests'); | ||
| const fs = require('fs'); | ||
| const fsp = fs.promises; | ||
| const { Blob, Buffer } = require('node:buffer'); | ||
| const stream = require('stream'); | ||
|
|
||
|
|
||
|
|
||
| metatests.testAsync('system/introspect', async (test) => { | ||
| const introspect = await wsClient.scaffold('system')('introspect')([ | ||
| 'auth', | ||
| 'console', | ||
| 'example', | ||
| 'files', | ||
| 'test', | ||
| ]); | ||
| test.strictSame(introspect?.auth?.restore?.[0], 'token'); | ||
| test.end(); | ||
| }); | ||
|
|
||
| metatests.testAsync('example/add', async (test) => { | ||
| const add = await wsClient.scaffold('example')('add')({ a: 1, b: 2 }); | ||
| test.strictSame(add, 3); | ||
| test.end(); | ||
| }); | ||
|
|
||
| metatests.testAsync('example/citiesByCountry', async (test) => { | ||
| const cities = await wsClient.scaffold('example')('citiesByCountry')({ | ||
| countryId: 1, | ||
| }); | ||
| test.strictEqual(cities?.result, 'success'); | ||
| test.strictEqual(Array.isArray(cities?.data), true); | ||
| test.end(); | ||
| }); | ||
|
|
||
| metatests.testAsync('example/customError', async (test) => { | ||
| try { | ||
| await wsClient.scaffold('example')('customError')(); | ||
| } catch (customError) { | ||
| test.errorCompare(customError, new Error('Return custom error', 12345)); | ||
| test.strictEqual(customError?.code, 12345); | ||
| } finally { | ||
| test.end(); | ||
| } | ||
| }); | ||
|
|
||
| metatests.testAsync('example/customException', async (test) => { | ||
| try { | ||
| await wsClient.scaffold('example')('customException')(); | ||
| } catch (customError) { | ||
| test.errorCompare(customError, new Error('Custom ecxeption', 12345)); | ||
| test.strictEqual(customError?.code, 12345); | ||
| } finally { | ||
| test.end(); | ||
| } | ||
| }); | ||
|
|
||
| metatests.testAsync('example/error', async (test) => { | ||
| try { | ||
| await wsClient.scaffold('example')('error')(); | ||
| } catch (Error) { | ||
| test.errorCompare(Error, new Error('Return error')); | ||
| } finally { | ||
| test.end(); | ||
| } | ||
| }); | ||
|
|
||
| metatests.testAsync('example/exception', async (test) => { | ||
|
|
||
| try { | ||
| await wsClient.scaffold('example')('exception')(); | ||
| } | ||
| catch(Error){ | ||
| test.errorCompare(Error, new Error('Example exception')); | ||
| } | ||
| finally { | ||
| test.end(); | ||
| } | ||
| // test.fail('Shoud never reach here'); | ||
| // test.end(); | ||
| }); | ||
|
|
||
| metatests.testAsync('example/getClientInfo', async (test) => { | ||
|
|
||
| const info = await wsClient.scaffold('example')('getClientInfo')(); | ||
|
|
||
| // console.log('info', info) | ||
| test.strictEqual(info?.result?.ip, '127.0.0.1'); | ||
| test.strictEqual(info?.result?.token, wsToken); | ||
| test.strictEqual(info?.result?.accountId, '2'); | ||
| test.end(); | ||
|
|
||
| }); | ||
|
|
||
| metatests.testAsync('example/redisSet + redisGet', async (test) => { | ||
| try { | ||
| const setting = await wsClient.scaffold('example')('redisSet')({ | ||
| key: 'MetarhiaExampleTest', | ||
| value: 1, | ||
| }); | ||
| const getting = await wsClient.scaffold('example')('redisGet')({ | ||
| key: 'MetarhiaExampleTest', | ||
| }); | ||
| // console.log({setting, getting}); | ||
| test.strictEqual(getting, '1'); | ||
| } catch (Error) { | ||
| test.errorCompare(Error, new Error('Example exception')); | ||
| } finally { | ||
| test.end(); | ||
| } | ||
| }); | ||
|
|
||
| // metatests.testAsync('example/resources', async (test) => { | ||
| // try { | ||
| // const resources = await wsClient.scaffold('example')('resources')(); | ||
| // test.strictEqual(resources?.total, null); | ||
| // // console.log({resources}); | ||
| // } catch (Error) { | ||
| // console.log(Error); | ||
| // } finally { | ||
| // test.end(); | ||
| // } | ||
| // }); | ||
|
|
||
| // metatests.testAsync('example/hook', async (test) => { | ||
| // let hook; | ||
| // try { | ||
| // hook = await client.httpCall('example', 1)('hook')(); | ||
|
|
||
| // console.log(hook) | ||
| // test.strictEqual(hook?.success, true); | ||
| // } | ||
| // catch(e){ | ||
| // console.log(e) | ||
| // } | ||
| // finally { | ||
| // test.end(hook); | ||
| // } | ||
|
|
||
| // }); | ||
|
|
||
|
|
||
|
|
||
| // metatests.testAsync('example/subscribe', async (test) => { | ||
| // try { | ||
| // const wait = await wsClient.scaffold('example')('wait')({ delay: 1000 }); | ||
| // // console.log(client.api.chat) | ||
| // test.strictEqual(wait, 'done'); | ||
| // } catch (Error) { | ||
| // console.log(Error); | ||
| // } finally { | ||
| // test.end(); | ||
| // } | ||
| // }); | ||
| /* | ||
| metatests.testAsync('example/uploadFile', async (test) => { | ||
| const original = 'uploading/sunset.jpg', uploaded = '../application/tmp/sunset_uploaded.jpg'; | ||
| // const buffer = Buffer.from(fs.readFileSync(original)); | ||
| // const blob = Uint8Array.from(buffer).buffer; | ||
| const content = await fsp.readFile(original); | ||
| const blob = new Blob([content]); | ||
| // blob.name = 'sunset.jpg'; | ||
| // console.log(blob.size) | ||
|
|
||
| // console.log(buffer) | ||
| const uploader = client.createBlobUploader(blob); | ||
| uploader.upload(); | ||
|
|
||
| // const readable = fs.createReadStream(original); | ||
| // const writable = client.createStream(original); | ||
| // readable.pipe(writable); | ||
| // // once readable is piped | ||
| // await wsClient.scaffold('example')('uploadFile')('sunset_uploaded.jpg', {stremId: writable.streamId}); | ||
|
|
||
| // const fixture = fs.readFileSync(original); | ||
| // const result = fs.readFileSync(uploaded); | ||
| // test.strictSame(result, fixture); | ||
| test.end(); | ||
| }); | ||
| */ | ||
|
|
||
| // metatests.testAsync('example/wait', async (test) => { | ||
| // try { | ||
| // const wait = await wsClient.scaffold('example')('wait')({ delay: 1000 }); | ||
| // test.strictEqual(wait, 'done'); | ||
| // } catch (Error) { | ||
| // console.log(Error); | ||
| // } finally { | ||
| // test.end(); | ||
| // } | ||
| // }); | ||
|
|
||
| }; | ||
|
|
||
| const connect = async () => { | ||
| const { Metacom } = require('metacom/lib/client'); | ||
|
|
||
| const wsUrl = 'ws://127.0.0.1:8000/api'; | ||
| const wsClient = Metacom.create(wsUrl); | ||
| await wsClient.open(); | ||
| const wsSignin = await wsClient.scaffold('auth')('signin')({ | ||
| login: 'marcus', | ||
| password: 'marcus', | ||
| }); | ||
|
|
||
| const wsToken = wsSignin?.token; | ||
| // const wsClient = null, wsToken = null; | ||
|
|
||
| const httpUrl = 'http://127.0.0.1:8000/api'; | ||
| const httpClient = Metacom.create(httpUrl); | ||
| await httpClient.open(); | ||
| const httpSignin = await httpClient.scaffold('auth')('signin')({ | ||
| login: 'marcus', | ||
| password: 'marcus', | ||
| }); | ||
| const httpToken = httpSignin?.token; | ||
| // const httpClient = null, httpToken = null; | ||
|
|
||
|
|
||
| // await client.load( 'auth', | ||
| // 'console', | ||
| // 'example', | ||
| // 'files', | ||
| // 'test'); | ||
|
|
||
|
|
||
|
|
||
| runTests(wsClient, wsToken, httpClient, httpToken); | ||
|
|
||
| }; | ||
|
|
||
| connect(); | ||
| // console.log(JSON.stringify({ a: 1, b: 2 })); | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.