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

Enable api.js test cases that were omitted #264

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

Conversation

KLarpen
Copy link
Contributor

@KLarpen KLarpen commented Dec 18, 2023

Closes: #263

The cause appears to be a tiny typo in a first guard line at

async cases(t, metacom) {
if (t) return;

Reverse of the check enables assertions and cases from the script. Console result of the npm t now shows its execution

13:14:16  W1   debug   ✅ Passed: Get room with domain.chat.getRoom (0.234334ms)
13:14:16  W1   debug   ✅ Passed: Send message with domain.chat.send (0.09725ms)
13:14:16  W1   debug   ✅ Passed: Chat test (1.097958ms)
13:14:16  W2   debug   127.0.0.1        POST    /api    200
13:14:16  W2   log     127.0.0.1        system/introspect
13:14:16  W2   debug   SELECT * FROM "Account" WHERE "login" = $1       [marcus]
13:14:17  W2   log     Logged user: marcus
13:14:17  W2   log     {
  createSession: {
    token: 'aNzY51hcAKpQVXtoS9xXzpnBGNF83NdMZ9YYEwG4ofbqhbZ2NG4u8MVV3FdW5db7',
    data: '{"accountId":"2"}',
    ip: '127.0.0.1',
    accountId: '2'
  }
}
13:14:17  W2   debug   INSERT INTO "Session" ("token", "data", "ip", "accountId") VALUES ($1, $2, $3, $4) RETURNING *   [aNzY51hcAKpQVXtoS9xXzpnBGNF83NdMZ9YYEwG4ofbqhbZ2NG4u8MVV3FdW5db7,{"accountId":"2"},127.0.0.1,2]
13:14:17  W2   debug   127.0.0.1        POST    /api    200
13:14:17  W2   log     127.0.0.1        auth/signin
13:14:17  W2   debug   127.0.0.1        POST    /api    200
13:14:17  W2   log     127.0.0.1        example/add
13:14:17  W1   debug   ✅ Passed: Call example.add({ a, b }) (2.3935ms)
13:14:17  W1   debug   ✅ Passed: Metacom over HTTP (112.830125ms)
13:14:17  W1   debug   127.0.0.1        GET     /demo.txt       200
13:14:17  W1   debug   ✅ Passed: Test to serve without cache (5.920542ms)
13:14:17  W3   debug   127.0.0.1        GET     /       200
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/ (6.396459ms)
13:14:17  W1   debug   127.0.0.1        GET     /console.js     200
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/console.js (2.886916ms)
13:14:17  W1   error   127.0.0.1        GET     /unknown        404
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/unknown (5.30275ms)
13:14:17  W1   error   127.0.0.1        GET     /unknown.png    404
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/unknown.png (1.873792ms)
13:14:17  W1   error   127.0.0.1        GET     /unknown/unknown        404
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/unknown/unknown (1.914459ms)
13:14:17  W1   error   127.0.0.1        GET     /unknown/unknown.png    404
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/unknown/unknown.png (1.583125ms)
13:14:17  W1   debug   127.0.0.1        GET     /article        200
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/article (1.344333ms)
13:14:17  W1   debug   127.0.0.1        GET     /article/file.txt       200
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/article/file.txt (1.523125ms)
13:14:17  W1   debug   127.0.0.1        GET     /article/name   200
13:14:17  W1   debug   ✅ Passed: Get static resource: http://127.0.0.1:8000/article/name (1.151792ms)
13:14:17  W1   debug   ✅ Passed: Static server test (31.472667ms)
13:14:17  W2   log     127.0.0.1        system/introspect
13:14:17  W2   debug   SELECT * FROM "Account" WHERE "login" = $1       [marcus]
13:14:17  W2   log     Logged user: marcus
13:14:17  W2   log     {
  createSession: {
    token: '1GSI5hJQuIX98Cb6uMVrctQDhpPUDfqLi9s0U2wowKN6t7MUSrm5YDcS69Bpf262',
    data: '{"accountId":"2"}',
    ip: '127.0.0.1',
    accountId: '2'
  }
}
13:14:17  W2   debug   INSERT INTO "Session" ("token", "data", "ip", "accountId") VALUES ($1, $2, $3, $4) RETURNING *   [1GSI5hJQuIX98Cb6uMVrctQDhpPUDfqLi9s0U2wowKN6t7MUSrm5YDcS69Bpf262,{"accountId":"2"},127.0.0.1,2]
13:14:17  W2   log     127.0.0.1        auth/signin
13:14:17  W2   log     127.0.0.1        example/add
13:14:17  W1   debug   ✅ Passed: Call example.add({ a, b }) (0.380292ms)
13:14:17  W1   debug   ✅ Passed: Metacom over Websocket (76.290041ms)
13:14:17  W1   debug   🟢 Passed 18, Failed: 0
  • tests and linter show no problems (npm t)
  • tests are added/updated
  • code is properly formatted (npm run fmt)

@KLarpen
Copy link
Contributor Author

KLarpen commented Dec 18, 2023

As an extra enhancement, I had wrapped signin test result assertions with named test case. That gives ability for test runner to measure execution time of the metacom.api.auth.signin operation.

13:31:09  W1   debug   ✅ Passed: Sign into session (91.059375ms)
13:31:09  W1   debug   ✅ Passed: Metacom over HTTP (110.810125ms)
...
13:31:09  W1   debug   ✅ Passed: Sign into session (65.835917ms)
13:31:09  W1   debug   ✅ Passed: Metacom over Websocket (71.862083ms)
13:31:09  W1   debug   🟢 Passed 20, Failed: 0

@KLarpen
Copy link
Contributor Author

KLarpen commented Dec 18, 2023

@tshemsedinov, beside fix and enhancement I'm looking to add another test case that calls API endpoint with logged access. Because Call example.add({ a, b }) currently public, so it doesn't test actual access after sign into session.

Created test case

await t.test(`Call logged endpoint`, async () => {
  const res = await metacom.api.example.wait({ delay: 1 });
  node.assert.strictEqual(res, 'done');
});

However I didn't place it into commit because it reveals that something not work with access to the logged endpoint through the HTTP transport at least during test run. WS transport at the same time passed this test case successfully.

13:42:05  W1   debug   ✅ Passed: Sign into session (82.932666ms)
13:42:05  W2   debug   127.0.0.1        POST    /api    200
13:42:05  W2   log     127.0.0.1        example/add
13:42:05  W1   debug   ✅ Passed: Call example.add({ a, b }) (2.259083ms)
13:42:05  W2   error   127.0.0.1        POST    /api    403     403     Forbidden
13:42:05  W2   error   127.0.0.1        POST    /api    403
13:42:05  W1   error   ❌ Failed: Call logged endpoint (2.017292ms)
Error: Forbidden
  HttpTransport.message (/node_modules/metacom/lib/client.js:114:28)
  /node_modules/metacom/lib/client.js:277:14
  process.processTicksAndRejections (node:internal/process/task_queues:95:5)
...
13:42:05  W1   debug   ✅ Passed: Sign into session (66.233208ms)
13:42:05  W2   log     127.0.0.1        example/add
13:42:05  W1   debug   ✅ Passed: Call example.add({ a, b }) (0.3925ms)
13:42:05  W2   log     127.0.0.1        example/wait
13:42:05  W1   debug   ✅ Passed: Call logged endpoint (1.755042ms)
13:42:05  W1   debug   ✅ Passed: Metacom over 

@KLarpen
Copy link
Contributor Author

KLarpen commented Dec 18, 2023

GitHub Workflow testing shows Error: connect ECONNREFUSED 127.0.0.1:5432 so the problem is that https://github.com/metarhia/Example/blob/master/.github/workflows/test.yml doesn't contain PostgreSQL container, but test for auth requests require the DB. I guess the if (t) return; guard was place specifically to switch off this test cases from execution during GH workflow.

@MarhiievHE already done great job of enhancing workflow environment in the branch client-test of his fork but it still not merged and PR #225 is open now (there is a lot of other stuff done). Part of that PR includes, for example:

Please give an advice @tshemsedinov . If the PR #225 is considered too big to land it now as a whole... maybe it's worth to extract some useful part of it into separate PR that you may be confident for apply?

@MarhiievHE thank's for your contribution! What is yours opinion?

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.

npm t omit execution of some test cases
1 participant