mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Extended our knex mock to only return specific fields/columns
no issue
This commit is contained in:
parent
89e4201b67
commit
fa4e2cf286
1 changed files with 15 additions and 0 deletions
|
@ -148,6 +148,21 @@ class KnexMock {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (dbEntry) {
|
if (dbEntry) {
|
||||||
|
// select fields
|
||||||
|
dbEntry = _.map(dbEntry, (obj) => {
|
||||||
|
let keys = query.sql.match(/select\s(\".*\"\,?)+\sfrom/);
|
||||||
|
|
||||||
|
if (keys) {
|
||||||
|
keys = keys[1];
|
||||||
|
keys = keys.replace(/"/g, '');
|
||||||
|
keys = keys.replace(/\s/g, '');
|
||||||
|
keys = keys.split(',');
|
||||||
|
return _.pick(obj, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
});
|
||||||
|
|
||||||
query.response(dbEntry);
|
query.response(dbEntry);
|
||||||
debug('#### Query end.\n');
|
debug('#### Query end.\n');
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue