Skip to content
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

Client (on server) tests for example interface #204

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

leonpolak
Copy link
Member

@leonpolak leonpolak commented Dec 26, 2022

I'm not sure how to test Metacom class in Client.js in Metacom package, for now, I have chosen to test the application code alongside to Example server.
However, there are some problems:

  1. No redis in lib inside application code (service is up and running)
  2. remoteMethod.js and webHook.js seem incomplete (at least I don't understand how I should run them)
  3. No lib.resmon, so no system info no subscription tests (yes, it's Windows, but at least some fallback strategy would be nice)
  4. I need some help with uploadFile method testing, like an example of uploading and confirming success.
  5. I'd like an example of event subscription test.

Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove commented code or can we uncommunt it?

test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
@tshemsedinov
Copy link
Member

Subscription:

api.example.on('resmon', (data) => {
  console.log({ data });
});

Copy link
Member

@nechaido nechaido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'll get back to you later on that.
  2. The best way to test remoteMethod is to modify it so that it returns the same arguments passed, and to check that the result matches the arguments on the client.
    To test the webhook I'd modify it to return all its arguments and check on the client that everything was resolved correctly.
  3. What would be your intention with the resmon test? You could add the resmon api to give reports on demand, but I'd prefer to see the test case before delving any deeper.
  4. To confirm results of the file upload we would need a predefined file fixture which we will upload to the server, and then we would access app's resources folder, read newly creted file and compare it to the original. Preferably small enough file that would fit into memory.
metatests.testAsync('file/upload', (test) => {
  const readable = fs.createReadable('path_to_fixture');
  const writable = client.createStream();
  readable.pipe(writable);
  // once readable is piped
  await client.socketCall('fileupload', {stremId: writable.streamId});
  
  const ficture = readSync(fixture);
  const result = readSync('path_to_new_file');
  test.strictSame(result, fixture);
});
  1. I'd use the existing api/chat PSEUDOCODE as follows:
metatests.testAsync('event subscription', (test) => {
  const MESSAGE = 'YER MESSAGE HERE, LAD';
  
  client.api.chat.on('message', msg => test.strictEquals(msg, MESSAGE));
});

test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated
const metatests = require('metatests');
const { Metacom } = require('metacom/lib/client');

let token = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the runTests argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, explain

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redefine runTests as

onst runTests = (client, token) => {

To get rid of global parameters.

test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated Show resolved Hide resolved
test/client.js Outdated

metatests.testAsync('example/exception', async (test) => {
try {
await client.socketCall('example')('exception')();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to catch an exception to check the message and custom data in custom exceptions and errors

test/client.js Outdated Show resolved Hide resolved
@leonpolak
Copy link
Member Author

I have tried a lot of approaches to make tests in test/client.js work (those attempts are partially commented out in the code), but it seems there are significant problems with metacom/lib/client.js

  1. There is still no redis in lib on server
  2. httpCall returns index.html to any POST request to /api
  3. So, there is no way to test uploading
  4. I still have no clear understanding how to test subscription
    Any help would be greatly appreciated, it's a bit of an obstacle to my further development.

@leonpolak
Copy link
Member Author

I took all updates and changed test/client.js accordingly. There are still some problems, old and new:

  1. HttpTransport does not work:
Error: Request timeout
    at Timeout._onTimeout (C:\usr\sites\metarhia\Example\node_modules\metacom\lib\client.js:181:22)
  1. No "accountId" field from rpc example/getClientInfo
  2. There is still no redis in lib on server
TypeError: Cannot read properties of undefined (reading 'set')
  method (\application\api\example.1\redisSet.js:4:36)

@tshemsedinov tshemsedinov mentioned this pull request May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants