Skip to content

Commit

Permalink
Add test cases for more data types
Browse files Browse the repository at this point in the history
  • Loading branch information
yym0329 committed Feb 27, 2024
1 parent 636a882 commit 5857c11
Showing 1 changed file with 214 additions and 0 deletions.
214 changes: 214 additions & 0 deletions test/middleware/validate_audit_period.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {},
Expand Down

0 comments on commit 5857c11

Please sign in to comment.