From c635334f834ac4b5291ae13ee4f531651bebf462 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Mon, 11 Dec 2023 09:50:30 +0100 Subject: [PATCH] Refactor utility imports and update test configurations The commit organizes the imports from utils directory by moving data processing functions to parsers.js. Also, it updates the test configurations by replacing the deprecated method getConfig with initConfig and changes parameters to make it more representative of deploy conditions. This results in a neater, more intuitive import schema and test set-up, enhancing code readability and understanding. --- tests/fixtures/wp-package.json | 4 ++-- tests/utils.test.js | 12 +++++------- tests/wpConfig.test.js | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/fixtures/wp-package.json b/tests/fixtures/wp-package.json index 1b006b3..dee4720 100644 --- a/tests/fixtures/wp-package.json +++ b/tests/fixtures/wp-package.json @@ -1,9 +1,9 @@ { - "name": "wordpress", "wordpress": { + "name": "wordpress", "version": "6.4.2", "language": "en_US", - "config": { + "WP_config": { "DB_NAME": "my_db_name", "DB_USER": "my_db_username", "DB_PASSWORD": "my_db_password", diff --git a/tests/utils.test.js b/tests/utils.test.js index 44b32b9..1c7eae8 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,17 +1,15 @@ -const { getConfig, getWordPressDownloadUrl, getDownloadUrl } = require('../lib/utils/data.js'); -const { generateSalt, replaceDbConstant, replaceDbConstantBool } = require("../lib/utils/wordpress.js"); -const {getDataFromFile} = require("../lib/utils/wordpress"); +const { getWordPressDownloadUrl, getDownloadUrl } = require('../lib/utils/data.js'); +const { generateSalt, replaceDbConstant, replaceDbConstantBool, getDataFromFile } = require("../lib/utils/parsers.js"); +const {initConfig} = require("../lib/utils/data"); describe('getConfig', () => { it('should read wp-package.json from the root folder and return the default configuration if the file does not exist', async () => { - const argv = undefined; // Call the function - const config = await getConfig(argv); + const config = await initConfig( 'tests', {version: '5.7.1', language: 'en_US'}); // Assert the result expect(config).toBeInstanceOf(Object); - expect(config.name).toBe('wordpress'); - expect(config.wordpress).toMatchObject({"config": {}}); + expect(config.wordpress).toMatchObject({"WP_config": {}, version: '5.7.1', language: 'en_US'}); expect(config.plugins).not.toBeFalsy(); }); }); diff --git a/tests/wpConfig.test.js b/tests/wpConfig.test.js index 3685f21..30fbeae 100644 --- a/tests/wpConfig.test.js +++ b/tests/wpConfig.test.js @@ -1,6 +1,6 @@ const fs = require("fs"); const path = require("path"); -const {parseWpConfig} = require("../lib/utils/wordpress"); +const {parseWpConfig} = require("../lib/utils/parsers.js"); describe('parseWpConfig with real file', () => {