diff --git a/test/middleware/validate_audit_period.spec.ts b/test/middleware/validate_audit_period.spec.ts index d0e9ec2..65aa0ec 100644 --- a/test/middleware/validate_audit_period.spec.ts +++ b/test/middleware/validate_audit_period.spec.ts @@ -18,6 +18,7 @@ const dummyAuditPeriod = { start: new Date('2023-01-01'), end: new Date('2023-06-30'), }; + const validDate = new Date('2023-04-01'); const invalidDate = new Date('2023-08-01'); @@ -170,6 +171,12 @@ describe('Middleware: validate_audit_period', function () { let budget: model.Budget; let income: model.Income; let expense: model.Expense; + let transaction: model.Transaction; + let transaction_record: model.TransactionRecord; + let card: model.Card; + let card_record: model.CardRecord; + let account: model.Account; + let account_record: model.AccountRecord; before(async function () { await initDB(); @@ -202,6 +209,50 @@ describe('Middleware: validate_audit_period', function () { amount: 1000000, BudgetId: budget.id, }); + transaction = await model.Transaction.create({ + incomeId: income.id, + projectAt: new Date('2023-04-01'), + manager: '김넙죽 매니저', + content: '운영비', + type: '공금카드', + amount: 5678, + transactionAt: new Date('2023-04-01'), + balance: 1234, + accountNumber: '1234-5678-1234-5678', + accountBank: '국민은행', + accountOwner: '통장주인', + }); + transaction_record = await model.TransactionRecord.create({ + TransactionId: transaction.id, + URI: 'http://receipt.com', + }); + card_record = await model.CardRecord.create({ + organizationId: organization.id, + year: dummyAuditPeriod.year, + half: dummyAuditPeriod.half, + URI: 'http://cardrecord.com', + }); + card = await model.Card.create({ + organizationId: organization.id, + year: dummyAuditPeriod.year, + half: dummyAuditPeriod.half, + name: '카드이름', + cardNumber: '1234-5678-1234-5678', + }); + account = await model.Account.create({ + organizationId: organization.id, + year: dummyAuditPeriod.year, + half: dummyAuditPeriod.half, + name: '계좌이름', + accountNumber: '1234-5678-1234-5678', + accountBank: '국민은행', + accountOwner: '통장주인', + }); + account_record = await model.AccountRecord.create({ + accountId: account.id, + URI: 'http://accountrecord.com', + note: 'account record note', + }); }); afterEach(async function () { @@ -213,6 +264,12 @@ describe('Middleware: validate_audit_period', function () { await model.Budget.destroy(options); await model.Income.destroy(options); await model.Expense.destroy(options); + await model.Transaction.destroy(options); + await model.TransactionRecord.destroy(options); + await model.Card.destroy(options); + await model.CardRecord.destroy(options); + await model.Account.destroy(options); + await model.AccountRecord.destroy(options); }); it('params에 year와 half가 존재할 경우 year와 half를 반환한다.', async function () { @@ -229,6 +286,20 @@ describe('Middleware: validate_audit_period', function () { expect(half).to.be.equal(dummyAuditPeriod.half); }); + it('body에 year와 half가 존재할 경우 year와 half를 반환한다.', async function () { + const req = { + params: {}, + body: { + year: dummyAuditPeriod.year, + half: dummyAuditPeriod.half, + }, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + it('params에 budget_id가 존재할 경우 budget_id를 이용해 year와 half를 반환한다.', async function () { const req = { params: { @@ -294,6 +365,149 @@ describe('Middleware: validate_audit_period', function () { expect(half).to.be.equal(dummyAuditPeriod.half); }); + it('params에 transaction_id가 존재할 경우 transaction_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: { + transaction_id: transaction.id, + }, + body: {}, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('body에 transaction_id가 존재할 경우 transaction_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: {}, + body: { + transaction_id: transaction.id, + }, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('params에 transaction_record_id가 존재할 경우 transaction_record_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: { + transaction_record_id: transaction_record.id, + }, + body: {}, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('params에 card_id가 존재할 경우 card_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: { + card_id: card.id, + }, + body: {}, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('body에 card_id가 존재할 경우 card_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: {}, + body: { + card_id: card.id, + }, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('params에 card_record_id가 존재할 경우 card_record_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: { + card_record_id: card_record.id, + }, + body: {}, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('body에 card_record_id가 존재할 경우 card_record_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: {}, + body: { + card_record_id: card_record.id, + }, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('params에 account_id가 존재할 경우 account_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: { + account_id: account.id, + }, + body: {}, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('body에 account_id가 존재할 경우 account_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: {}, + body: { + account_id: account.id, + }, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('params에 account_record_id가 존재할 경우 account_record_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: { + account_record_id: account_record.id, + }, + body: {}, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + + it('body에 account_record_id가 존재할 경우 account_record_id를 이용해 year와 half를 반환한다.', async function () { + const req = { + params: {}, + body: { + account_record_id: account_record.id, + }, + } as any as Request; + + const { year, half } = await findYearAndHalf(req); + expect(year).to.be.equal(dummyAuditPeriod.year); + expect(half).to.be.equal(dummyAuditPeriod.half); + }); + it('params과 body를 이용해 year와 half를 찾을 수 없는 경우 BadRequestError를 발생시킨다.', async function () { const req = { params: {},