Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app/composables/run_function_when_microservices_connected.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useInfraStore } from "@ogw_front/stores/infra";

export function run_function_when_microservices_connected(function_to_run) {
export function runFunctionWhenMicroservicesConnected(functionToRun) {
const infraStore = useInfraStore();
const { microservices_connected } = storeToRefs(infraStore);
console.log("inside microservices_connected", microservices_connected.value);
if (microservices_connected.value) {
function_to_run();
} else {
watch(microservices_connected, (value) => {
functionToRun();
}
watch(
microservices_connected,
(value) => {
if (value) {
console.log("watch microservices_connected", value);
function_to_run();
functionToRun();
}
});
}
},
{ once: true },
);
}
16 changes: 8 additions & 8 deletions app/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ function extensionsConf(projectName) {
return extensionsConfig;
}

function addExtensionToConf(projectName, { extensionID, extensionPath }) {
function addExtensionToConf(projectName, { extensionId, extensionPath }) {
const projectConfig = projectConf(projectName);
projectConfig.set(`extensions.${extensionID}.path`, extensionPath);
projectConfig.set(`extensions.${extensionId}.path`, extensionPath);
}

async function removeExtensionFromConf(projectName, extensionID) {
async function removeExtensionFromConf(projectName, extensionId) {
const projectConfig = projectConf(projectName);
const extensionArchivePath = extensionPathFromConf(projectName, extensionID);
const extensionArchivePath = extensionPathFromConf(projectName, extensionId);

await unlink(extensionArchivePath, (error) => {
if (error) {
throw error;
}
console.log(`${extensionArchivePath} was deleted`);
});
projectConfig.delete(`extensions.${extensionID}`);
console.log(`${extensionID} was deleted from ${projectName} config`);
projectConfig.delete(`extensions.${extensionId}`);
console.log(`${extensionId} was deleted from ${projectName} config`);
}

function extensionPathFromConf(projectName, extensionID) {
function extensionPathFromConf(projectName, extensionId) {
const projectConfig = projectConf(projectName);
return projectConfig.get(`extensions.${extensionID}.path`);
return projectConfig.get(`extensions.${extensionId}.path`);
}

export {
Expand Down
4 changes: 2 additions & 2 deletions app/utils/local/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function generateProjectFolderPath(projectName) {
return path.join(os.tmpdir(), projectName.replaceAll("/", "_"), uuidv4());
}

function extensionFolderPath(projectFolderPath, extensionID) {
return path.join(projectFolderPath, "extensions", extensionID);
function extensionFolderPath(projectFolderPath, extensionId) {
return path.join(projectFolderPath, "extensions", extensionId);
}

async function lookForLocalExtensionDistPath(rootPath, extentionRepoName, frontendFile) {
Expand Down
6 changes: 3 additions & 3 deletions server/api/extensions/run.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export default defineEventHandler(async (event) => {
const extensionsConfig = extensionsConf(projectName);

const extensionsArray = await Promise.all(
Object.keys(extensionsConfig).map(async (extensionID) => {
const extensionPath = extensionsConfig[extensionID].path;
Object.keys(extensionsConfig).map(async (extensionId) => {
const extensionPath = extensionsConfig[extensionId].path;
const unzippedExtensionPath = await unzipFile(
extensionPath,
extensionFolderPath(projectFolderPath, extensionID),
extensionFolderPath(projectFolderPath, extensionId),
);
const metadataPath = path.join(unzippedExtensionPath, "metadata.json");
const metadataContent = await fs.promises.readFile(metadataPath, "utf8");
Expand Down
2 changes: 1 addition & 1 deletion server/api/extensions/upload.put.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default defineEventHandler(async (event) => {
const metadata = JSON.parse(metadataJson);
const { id } = metadata;
await addExtensionToConf(projectName, {
extensionID: id,
extensionId: id,
extensionPath: file,
});
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Local imports
import { Status } from "@ogw_front/utils/status";
import { run_function_when_microservices_connected } from "@ogw_front/composables/run_function_when_microservices_connected";
import { runFunctionWhenMicroservicesConnected } from "@ogw_front/composables/run_function_when_microservices_connected";
import { setupActivePinia } from "@ogw_tests/utils";
import { useBackStore } from "@ogw_front/stores/back";
import { useInfraStore } from "@ogw_front/stores/infra";
Expand Down Expand Up @@ -38,20 +38,20 @@
viewerStore.$patch({ status: Status.NOT_CONNECTED });
});

test("microservices not connected", () => {
const spy = vi.spyOn(dumb_obj, "dumb_method");
run_function_when_microservices_connected(dumb_obj.dumb_method);
runFunctionWhenMicroservicesConnected(dumb_obj.dumb_method);
backStore.$patch({ status: Status.NOT_CONNECTED });
viewerStore.$patch({ status: Status.NOT_CONNECTED });
expect(spy).not.toHaveBeenCalled();
});

Check warning on line 47 in tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js

View workflow job for this annotation

GitHub Actions / test / oxlint

vitest(require-test-timeout)

Test is missing a timeout.

test("microservices connected", async () => {
const spy = vi.spyOn(dumb_obj, "dumb_method");
run_function_when_microservices_connected(dumb_obj.dumb_method);
runFunctionWhenMicroservicesConnected(dumb_obj.dumb_method);
backStore.$patch({ status: Status.CONNECTED });
viewerStore.$patch({ status: Status.CONNECTED });
await flushPromises();
expect(spy).toHaveBeenCalledWith();
});

Check warning on line 56 in tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js

View workflow job for this annotation

GitHub Actions / test / oxlint

vitest(require-test-timeout)

Test is missing a timeout.
});
Loading