Open f22linhe opened 2 months ago
It seems like the microservice is not working at the moment. I have seen that there is an open issue that might fix this, so I will put this on hold and make a new branch when that issue has been resolved.
I have started making a test, I'm guessing it's about 80% done, only needs some small fixes when the ms has been fixed.
<?php
include "../../../../Shared/test.php";
$testsData = array(
'update password (user)' => array(
'expected-output' => '{}',
'query-before-test-1' => "INSERT INTO listentries(lid, entryname,cid,vers,creator) VALUES (9789,'TestEntry',1885,1337,101);",
'query-before-test-2' => "INSERT INTO quiz(id, cid,vers, qname) VALUES (333,1885,1337,'testQuiz')",
'query-before-test-3' => "INSERT INTO userAnswer(aid,cid,vers, quiz,moment, useranswer) VALUES (978,1885,1337,333,9789,'hsanswer');",
'query-after-test-1' => "DELETE FROM userAnswer WHERE aid = 978;",
'query-after-test-2' => "DELETE FROM quiz WHERE id = 333;",
'query-after-test-3' => "DELETE FROM listentries WHERE lid = 9789;",
'service' => 'http://localhost/LenaSYS/DuggaSys/microservices/highscoreService/highscoreService_ms.php',
'service-data' => serialize(array( // Data that service needs to execute function
'username' => 'brom',
'password' => 'password',
//'opt' => '', doesnt seem to use an opt at the moment.
'courseid' => '1885',
'coursename' => 'Testing-Course',
'coursevers' => '1337',
'did' => '333',
'lid' => '9789',
)),
'filter-output' => serialize(array( // Filter what output to use in assert test, use none to use all ouput from service
'debug',
'highscores',
'user',
)),
),
);
testHandler($testsData, true); // 2nd argument (prettyPrint): true = prettyprint (HTML), false = raw JSON
The other issue has been resolved and it is now possible to receive output from the microservice.
I have however not been able to retrieve any scores from users during testing as described in PR #15585 . All I'm receiving is usernames with null scores. I think maybe the highscoreservice isn't working as it should or there might be a problem with my personal setup.
I will let go of this issue and maybe someone else can make it work.
Rebased the branch to g2-2024-v7. Will see if I can fix the problem.
I find it strange that retrievehighscoreService fetches username and score, but there is no join of the tables user and userAnswer. In fact, there is no way to join them since userAnswer is not tied to user by any foreign key. It is instead tied to a quiz. Therefore, there is no reason to fetch the usernames since they are not tied to the answers.
Highscores are shown when you press the button that says "top 10" on a test. However, this does not work. None are shown except when logged in and then a13andka is shown with a null score at all duggas.
For example in microservices/showDuggaservice we have the microservice updateActiveUsers_ms.php. It needs these parameters in: $hash=getOP('hash'); $AUtoken=getOP('AUtoken');
And depending on the values of the parameters it should have a expected-output, since it returns: echo json_encode($active);
We should create these tests similarly to how tests have been made for tests in e.g. sectionedservice_Test.php (e.g. getCourseGroupsAndMembers). If some test data need to exist in the database, create the inserts with the tables and values for your specific test. e.g.: 'query-before-test-1' => "INSERT INTO user_course (cid, vers, uid,groups,access) VALUES (1885,1337,3, 'No_2','W'), (1885,1337,101, 'No_2','W');",
And also delete the test data after, e.g.: 'query-after-test-1' => "DELETE FROM user_course WHERE uid=3 AND cid=1885;",
The test istself should be created in LenaSYS/DuggaSys/tests/microservices/ in a folder named highscoreService. So according to the example above: LenaSYS/DuggaSys/tests/microservices/showDuggaService/updateActiveUsers_ms_test.php
Note, this issue cannot be resolved before these two issues has been resolved:
Create microservice highscoreservice_ms.php #15352
Create a retrievehighscoreService microservice #15353