Skip to content

Commit 29865ea

Browse files
epankouRailag
authored andcommitted
bug(fix) flow excessive fields (ENG-545)
1 parent f09c16d commit 29865ea

File tree

3 files changed

+38
-39
lines changed

3 files changed

+38
-39
lines changed

src/sequelize/managers/flow-manager.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,19 @@ class FlowManager extends BaseManager {
3737
}, {transaction: transaction})
3838
}
3939

40-
async findAllExcludeFields(where, transaction) {
40+
async findAllWithAttributes(where, attributes, transaction) {
4141
return Flow.findAll({
4242
where: where,
43-
attributes: {
44-
exclude: [
45-
'created_at',
46-
'updated_at',
47-
'updatedById',
48-
'userId'
49-
]}}, {transaction: transaction})
43+
attributes: attributes},
44+
{transaction: transaction})
5045
}
5146

52-
async findOneExcludeFields(where, transaction) {
47+
async findOneWithAttributes(where, attributes, transaction) {
5348
return Flow.findOne({
5449
where: where,
55-
attributes: {
56-
exclude: [
57-
'created_at',
58-
'updated_at',
59-
'updatedById',
60-
'userId'
61-
]}}, {transaction: transaction})
50+
attributes: attributes
51+
},
52+
{transaction: transaction})
6253
}
6354
}
6455

src/services/flow-service.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ const getUserFlows = async function (user, isCLI, transaction) {
8989
userId: user.id
9090
};
9191

92-
const flows = await FlowManager.findAllExcludeFields(flow, transaction);
92+
const attributes = {exclude: ["created_at", "updated_at"]};
93+
const flows = await FlowManager.findAllWithAttributes(flow, attributes, transaction);
9394
return {
9495
flows: flows
9596
}
9697
};
9798

9899
const getAllFlows = async function (isCLI, transaction) {
99-
const flows = await FlowManager.findAll({}, transaction);
100+
const attributes = {exclude: ['created_at', 'updated_at']};
101+
const flows = await FlowManager.findAllWithAttributes({}, attributes, transaction);
100102
return {
101103
flows: flows
102104
}
@@ -107,7 +109,9 @@ const getFlow = async function (flowId, user, isCLI, transaction) {
107109
? {id: flowId}
108110
: {id: flowId, userId: user.id};
109111

110-
const flow = await FlowManager.findOneExcludeFields(where, transaction);
112+
const attributes = {exclude: ["created_at", "updated_at"]};
113+
114+
const flow = await FlowManager.findOneWithAttributes(where, attributes, transaction);
111115

112116
if (!flow) {
113117
throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_FLOW_ID, flowId))

test/src/services/flow-service.test.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ describe('Flow Service', () => {
279279

280280
beforeEach(() => {
281281
$sandbox.stub(Validator, 'validate').returns($validatorResponse);
282-
$sandbox.stub(FlowManager, 'findOneExcludeFields').returns($findExcludedFlowResponse);
282+
$sandbox.stub(FlowManager, 'findOneWithAttributes').returns($findExcludedFlowResponse);
283283
$sandbox.stub(FlowManager, 'findOne').returns($findFlowResponse);
284284
$sandbox.stub(AppHelper, 'deleteUndefinedFields').returns($deleteUndefinedFieldsResponse);
285285
$sandbox.stub(FlowManager, 'update').returns($updateFlowResponse);
@@ -301,24 +301,25 @@ describe('Flow Service', () => {
301301
});
302302

303303
context('when Validator#validate() succeeds', () => {
304-
it('calls FlowManager#findOneExcludeFields() with correct args', async () => {
304+
it('calls FlowManager#findOneWithAttributes() with correct args', async () => {
305305
await $subject;
306306

307307
const where = isCLI
308308
? {id: flowId}
309309
: {id: flowId, userId: user.id};
310-
expect(FlowManager.findOneExcludeFields).to.have.been.calledWith(where, transaction);
310+
const attributes = {exclude: ["created_at", "updated_at"]};
311+
expect(FlowManager.findOneWithAttributes).to.have.been.calledWith(where, attributes, transaction);
311312
});
312313

313-
context('when FlowManager#findOneExcludeFields() fails', () => {
314+
context('when FlowManager#findOneWithAttributes() fails', () => {
314315
def('findExcludedFlowResponse', () => Promise.reject(error));
315316

316317
it(`fails with ${error}`, () => {
317318
return expect($subject).to.be.rejectedWith(error);
318319
})
319320
});
320321

321-
context('when FlowManager#findOneExcludeFields() succeeds', () => {
322+
context('when FlowManager#findOneWithAttributes() succeeds', () => {
322323
it('calls FlowManager#findOne() with correct args', async () => {
323324
await $subject;
324325

@@ -433,23 +434,24 @@ describe('Flow Service', () => {
433434
def('findExcludedFlowResponse', () => Promise.resolve());
434435

435436
beforeEach(() => {
436-
$sandbox.stub(FlowManager, 'findAllExcludeFields').returns($findExcludedFlowResponse);
437+
$sandbox.stub(FlowManager, 'findAllWithAttributes').returns($findExcludedFlowResponse);
437438
});
438439

439-
it('calls FlowManager#findAllExcludeFields() with correct args', async () => {
440+
it('calls FlowManager#findAllWithAttributes() with correct args', async () => {
440441
await $subject;
441-
expect(FlowManager.findAllExcludeFields).to.have.been.calledWith(flow, transaction);
442+
const attributes = {exclude: ["created_at", "updated_at"]};
443+
expect(FlowManager.findAllWithAttributes).to.have.been.calledWith(flow, attributes, transaction);
442444
});
443445

444-
context('when FlowManager#findAllExcludeFields() fails', () => {
446+
context('when FlowManager#findAllWithAttributes() fails', () => {
445447
def('findExcludedFlowResponse', () => Promise.reject(error));
446448

447449
it(`fails with ${error}`, () => {
448450
return expect($subject).to.be.rejectedWith(error);
449451
})
450452
});
451453

452-
context('when FlowManager#findAllExcludeFields() succeeds', () => {
454+
context('when FlowManager#findAllWithAttributes() succeeds', () => {
453455
it('fulfills the promise', () => {
454456
return expect($subject).to.eventually.have.property('flows');
455457
})
@@ -465,23 +467,24 @@ describe('Flow Service', () => {
465467
def('findAllFlowsResponse', () => Promise.resolve());
466468

467469
beforeEach(() => {
468-
$sandbox.stub(FlowManager, 'findAll').returns($findAllFlowsResponse);
470+
$sandbox.stub(FlowManager, 'findAllWithAttributes').returns($findAllFlowsResponse);
469471
});
470472

471-
it('calls FlowManager#findAll() with correct args', async () => {
473+
it('calls FlowManager#findAllWithAttributes() with correct args', async () => {
472474
await $subject;
473-
expect(FlowManager.findAll).to.have.been.calledWith({}, transaction);
475+
const attributes = {exclude: ['created_at', 'updated_at']};
476+
expect(FlowManager.findAllWithAttributes).to.have.been.calledWith({}, attributes, transaction);
474477
});
475478

476-
context('when FlowManager#findAll() fails', () => {
479+
context('when FlowManager#findAllWithAttributes() fails', () => {
477480
def('findAllFlowsResponse', () => Promise.reject(error));
478481

479482
it(`fails with ${error}`, () => {
480483
return expect($subject).to.be.rejectedWith(error);
481484
})
482485
});
483486

484-
context('when FlowManager#findAll() succeeds', () => {
487+
context('when FlowManager#findAllWithAttributes() succeeds', () => {
485488
it('fulfills the promise', () => {
486489
return expect($subject).to.eventually.have.property('flows');
487490
})
@@ -502,26 +505,27 @@ describe('Flow Service', () => {
502505
def('findFlowResponse', () => Promise.resolve({}));
503506

504507
beforeEach(() => {
505-
$sandbox.stub(FlowManager, 'findOneExcludeFields').returns($findFlowResponse);
508+
$sandbox.stub(FlowManager, 'findOneWithAttributes').returns($findFlowResponse);
506509
});
507510

508-
it('calls FlowManager#findOneExcludeFields() with correct args', async () => {
511+
it('calls FlowManager#findOneWithAttributes() with correct args', async () => {
509512
await $subject;
510513
const where = isCLI
511514
? {id: flowId}
512515
: {id: flowId, userId: user.id};
513-
expect(FlowManager.findOneExcludeFields).to.have.been.calledWith(where, transaction);
516+
const attributes = {exclude: ["created_at", "updated_at"]};
517+
expect(FlowManager.findOneWithAttributes).to.have.been.calledWith(where, attributes, transaction);
514518
});
515519

516-
context('when FlowManager#findOneExcludeFields() fails', () => {
520+
context('when FlowManager#findOneWithAttributes() fails', () => {
517521
def('findFlowResponse', () => Promise.reject(error));
518522

519523
it(`fails with ${error}`, () => {
520524
return expect($subject).to.be.rejectedWith(error);
521525
})
522526
});
523527

524-
context('when FlowManager#findOneExcludeFields() succeeds', () => {
528+
context('when FlowManager#findOneWithAttributes() succeeds', () => {
525529
it('fulfills the promise', () => {
526530
return expect($subject).to.eventually.deep.equal({});
527531
})

0 commit comments

Comments
 (0)