fix: test for get-launch-apps

This commit is contained in:
KernelDeimos 2025-01-09 11:10:41 -05:00
parent 3097b86597
commit 740fdb592e
4 changed files with 65 additions and 48 deletions

8
package-lock.json generated
View File

@ -2461,9 +2461,9 @@
"link": true
},
"node_modules/@heyputer/kv.js": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/@heyputer/kv.js/-/kv.js-0.1.8.tgz",
"integrity": "sha512-bNj2qo1keALKR6luFXRWJJ1mtoN2oozmq9SD6/U2O3uEcrnR1NhWKYuwl4pORixA5NL1ez4jbkwUxuTRT0V+iQ==",
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/@heyputer/kv.js/-/kv.js-0.1.9.tgz",
"integrity": "sha512-4zmS/kMp/glMmw4h+OYkD+AribMAdfFj1/1AyLpO/bgQELjM7ZsGX7VeaqtbgiNAT5loeDd3ER9PtP9KUULuHg==",
"dependencies": {
"minimatch": "^9.0.0"
}
@ -17696,7 +17696,7 @@
"@anthropic-ai/sdk": "^0.26.1",
"@aws-sdk/client-polly": "^3.622.0",
"@aws-sdk/client-textract": "^3.621.0",
"@heyputer/kv.js": "^0.1.8",
"@heyputer/kv.js": "^0.1.9",
"@heyputer/multest": "^0.0.2",
"@heyputer/putility": "^1.0.0",
"@mistralai/mistralai": "^1.3.4",

View File

@ -10,7 +10,7 @@
"@anthropic-ai/sdk": "^0.26.1",
"@aws-sdk/client-polly": "^3.622.0",
"@aws-sdk/client-textract": "^3.621.0",
"@heyputer/kv.js": "^0.1.8",
"@heyputer/kv.js": "^0.1.9",
"@heyputer/multest": "^0.0.2",
"@heyputer/putility": "^1.0.0",
"@mistralai/mistralai": "^1.3.4",

View File

@ -17,12 +17,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
"use strict"
const express = require('express');
const router = express.Router();
const auth = require('../middleware/auth.js');
const { get_app } = require('../helpers.js');
const { DB_READ } = require('../services/database/consts.js');
const { stream_to_buffer } = require('../util/streamutil.js');
const iconify_apps = async (context, { apps, size }) => {
return await Promise.all(apps.map(async app => {

View File

@ -91,6 +91,21 @@ const get_mock_context = () => {
}
}
};
const recommendedApps_mock = {
get_recommended_apps: async ({ icon_size }) => {
return data_mockapps
.filter(app => apps_names_expected_to_exist.includes(app.name))
.map(app => ({
uuid: app.uid,
name: app.name,
title: app.title,
icon: app.icon,
godmode: app.godmode,
maximize_on_start: app.maximize_on_start,
index_url: app.index_url,
}));
}
}
const services_mock = {
get: (key) => {
if (key === 'database') {
@ -98,6 +113,9 @@ const get_mock_context = () => {
get: () => database_mock,
}
}
if ( key === 'recommended-apps' ) {
return recommendedApps_mock;
}
}
};
@ -146,52 +164,55 @@ describe('GET /launch-apps', () => {
req_mock.query = {};
await get_launch_apps(req_mock, res_mock);
expect(res_mock.send.calledOnce).to.equal(true, 'res.send should be called once');
if ( false ) {
const call = res_mock.send.firstCall;
response = call.args[0];
console.log('response', response);
expect(res_mock.send.calledOnce).to.equal(true, 'res.send should be called once');
expect(response).to.be.an('object');
const call = res_mock.send.firstCall;
response = call.args[0];
console.log('response', response);
expect(response).to.have.property('recommended');
expect(response.recommended).to.be.an('array');
expect(response.recommended).to.have.lengthOf(apps_names_expected_to_exist.length);
expect(response.recommended).to.deep.equal(
data_mockapps
.filter(app => apps_names_expected_to_exist.includes(app.name))
.map(app => ({
uuid: app.uid,
name: app.name,
title: app.title,
icon: app.icon,
godmode: app.godmode,
maximize_on_start: app.maximize_on_start,
index_url: app.index_url,
}))
);
expect(response).to.be.an('object');
expect(response).to.have.property('recent');
expect(response.recent).to.be.an('array');
expect(response.recent).to.have.lengthOf(data_appopens.length);
expect(response.recent).to.deep.equal(
data_mockapps
.filter(app => data_appopens.map(app_open => app_open.app_uid).includes(app.uid))
.map(app => ({
uuid: app.uid,
name: app.name,
title: app.title,
icon: app.icon,
godmode: app.godmode,
maximize_on_start: app.maximize_on_start,
index_url: app.index_url,
}))
);
expect(response).to.have.property('recommended');
expect(response.recommended).to.be.an('array');
expect(response.recommended).to.have.lengthOf(apps_names_expected_to_exist.length);
expect(response.recommended).to.deep.equal(
data_mockapps
.filter(app => apps_names_expected_to_exist.includes(app.name))
.map(app => ({
uuid: app.uid,
name: app.name,
title: app.title,
icon: app.icon,
godmode: app.godmode,
maximize_on_start: app.maximize_on_start,
index_url: app.index_url,
}))
);
expect(response).to.have.property('recent');
expect(response.recent).to.be.an('array');
expect(response.recent).to.have.lengthOf(data_appopens.length);
expect(response.recent).to.deep.equal(
data_mockapps
.filter(app => data_appopens.map(app_open => app_open.app_uid).includes(app.uid))
.map(app => ({
uuid: app.uid,
name: app.name,
title: app.title,
icon: app.icon,
godmode: app.godmode,
maximize_on_start: app.maximize_on_start,
index_url: app.index_url,
}))
);
}
// << HOW TO FIX >>
// If you updated the list of recommended apps,
// you can simply update this number to match the new length
expect(spies.get_app.callCount).to.equal(26);
// expect(spies.get_app.callCount).to.equal(3);
}
// Second call