Skip to content

Commit

Permalink
refactor: async function should have await expression
Browse files Browse the repository at this point in the history
  • Loading branch information
acodeninja committed Sep 24, 2024
1 parent 25b45f8 commit 4b1fee8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
16 changes: 8 additions & 8 deletions src/engine/FileEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class FileEngine extends Engine {
* Retrieves a model by its ID from the file system.
*
* @param {string} id - The ID of the model to retrieve.
* @returns {Object} The parsed model data.
* @returns {Promise<Object>} The parsed model data.
* @throws {Error} Throws if the file cannot be read or parsed.
*/
static async getById(id) {
static getById(id) {
return this.configuration.filesystem
.readFile(join(this.configuration.path, `${id}.json`))
.then((b) => b.toString())
Expand All @@ -68,10 +68,10 @@ class FileEngine extends Engine {
* Retrieves the index for a given model from the file system.
*
* @param {Model.constructor?} model - The model for which the index is retrieved.
* @returns {Object} The parsed index data.
* @returns {Promise<Object>} The parsed index data.
* @throws {Error} Throws if the file cannot be read.
*/
static async getIndex(model) {
static getIndex(model) {
return this.configuration.filesystem
.readFile(join(this.configuration.path, model.toString(), '_index.json'))
.then((b) => b.toString())
Expand Down Expand Up @@ -128,10 +128,10 @@ class FileEngine extends Engine {
* Retrieves the compiled search index for a model from the file system.
*
* @param {Model.constructor} model - The model for which the search index is retrieved.
* @returns {Object} The parsed compiled search index.
* @returns {Promise<Object>} The parsed compiled search index.
* @throws {Error} Throws if the file cannot be read.
*/
static async getSearchIndexCompiled(model) {
static getSearchIndexCompiled(model) {
return this.configuration.filesystem
.readFile(join(this.configuration.path, model.toString(), '_search_index.json'))
.then((b) => b.toString())
Expand All @@ -142,10 +142,10 @@ class FileEngine extends Engine {
* Retrieves the raw search index for a model from the file system.
*
* @param {Model.constructor} model - The model for which the raw search index is retrieved.
* @returns {Object} The parsed raw search index.
* @returns {Promise<Object>} The parsed raw search index.
* @throws {Error} Throws if the file cannot be read.
*/
static async getSearchIndexRaw(model) {
static getSearchIndexRaw(model) {
return this.configuration.filesystem
.readFile(join(this.configuration.path, model.toString(), '_search_index_raw.json'))
.then((b) => b.toString())
Expand Down
30 changes: 10 additions & 20 deletions src/engine/HTTPEngine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,14 @@ test('HTTPEngine.put(model) when the engine fails to put a compiled search index
return Promise.resolve({
ok: false,
status: 500,
json: async () => {
throw new Error();
},
json: () => Promise.reject(new Error()),
});
}

return Promise.resolve({
ok: true,
status: 200,
json: async () => ({}),
json: () => Promise.resolve({}),
});
});

Expand Down Expand Up @@ -332,16 +330,14 @@ test('HTTPEngine.put(model) when the engine fails to put a raw search index', as
return Promise.resolve({
ok: false,
status: 500,
json: async () => {
throw new Error();
},
json: () => Promise.reject(new Error()),
});
}

return Promise.resolve({
ok: true,
status: 200,
json: async () => ({}),
json: () => Promise.resolve({}),
});
});

Expand Down Expand Up @@ -388,16 +384,14 @@ test('HTTPEngine.put(model) when putting an index fails', async t => {
return Promise.resolve({
ok: false,
status: 500,
json: async () => {
throw new Error();
},
json: () => Promise.reject(new Error()),
});
}

return Promise.resolve({
ok: true,
status: 200,
json: async () => ({}),
json: () => Promise.resolve({}),
});
});

Expand Down Expand Up @@ -444,16 +438,14 @@ test('HTTPEngine.put(model) when the initial model put fails', async t => {
return Promise.resolve({
ok: false,
status: 500,
json: async () => {
throw new Error();
},
json: () => Promise.reject(new Error()),
});
}

return Promise.resolve({
ok: true,
status: 200,
json: async () => ({}),
json: () => Promise.resolve({}),
});
});

Expand Down Expand Up @@ -489,16 +481,14 @@ test('HTTPEngine.put(model) when the engine fails to put a linked model', async
return Promise.resolve({
ok: false,
status: 500,
json: async () => {
throw new Error();
},
json: () => Promise.reject(new Error()),
});
}

return Promise.resolve({
ok: true,
status: 200,
json: async () => ({}),
json: () => Promise.resolve({}),
});
});

Expand Down

0 comments on commit 4b1fee8

Please sign in to comment.