Skip to content

Commit

Permalink
chore: migrate to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
stu01509 committed Oct 26, 2023
1 parent d2e0545 commit 3722c6c
Show file tree
Hide file tree
Showing 7 changed files with 1,901 additions and 353 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Init - Set up yarn environment
run: npm install -g yarn

- name: Install dependencies
run: yarn

- name: Unit Test
run: yarn test
12 changes: 7 additions & 5 deletions .github/workflows/main_etf-line-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Init - Set up yarn environment
run: npm install -g yarn

- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Install dependencies
run: yarn

- name: Unit Test
run: yarn test

- name: Zip artifact for deployment
run: zip release.zip ./* -r
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"start": "node app.js",
"test": "mocha --timeout 5000",
"test": "jest",
"test:report": "jest",
"dev": "nodemon app.js"
},
"repository": {
Expand All @@ -22,17 +23,21 @@
},
"homepage": "https://github.com/stu01509/ETF-Line-Bot#readme",
"dependencies": {
"@types/node": "^20.8.9",
"dotenv": "^10.0.0",
"linebot": "^1.6.1",
"mongoose": "^5.5.15",
"node-fetch": "^2.6.1"
"node-fetch": "^2.6.1",
"typescript": "^5.2.2"
},
"devDependencies": {
"@types/jest": "^29.5.6",
"eslint": "^7.31.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.23.4",
"mocha": "^9.0.3",
"jest": "^29.7.0",
"nodemon": "^1.3.3",
"should": "^13.2.3"
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1"
}
}
File renamed without changes.
82 changes: 82 additions & 0 deletions services/etf/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const etf = require('./index');

describe('services > etf', () => {
describe('Given the user wants to get the etf result', () => {
describe('When the user not execute loadEtfInfo', () => {
it('should able to get the empty result', async () => {
const result = await etf.getEtfInfo();

expect(result).toEqual([]);
expect(result.length).toEqual(0);
});
});

describe('When the user execute loadEtfInfo', () => {
it('should albe to get the result', async () => {
await etf.loadEtfInfo();

const result = await etf.getEtfInfo();

expect(result).not.toEqual([]);
expect(result.length).toBeGreaterThan(0);
});
});

describe('When the wants to search the 0050', () => {
it('should able to get the 0050', async () => {
await etf.loadEtfInfo();

const result = (await etf.getEtfInfo()).filter((item) => item.a === '0050');

expect(result[0]).toEqual({
a: '0050',
b: '元大台灣50',
c: 2327500000,
d: -14500000,
e: 121.75,
f: 121.71,
g: 0.03,
h: '123.9900',
i: '20231026',
j: '13:45:00',
k: '1',
});
expect(result.length).toEqual(1);
});
});

describe('When the wants to search the 0056', () => {
it('should able to get the 0056', async () => {
await etf.loadEtfInfo();

const result = (await etf.getEtfInfo()).filter((item) => item.a === '0056');

expect(result[0]).toEqual({
a: '0056',
b: '元大高股息',
c: 6934534000,
d: 31500000,
e: 33.1,
f: 32.9,
g: 0.61,
h: '33.4800',
i: '20231026',
j: '13:45:00',
k: '1',
});
expect(result.length).toEqual(1);
});
});

describe('When the wants to search no exist etf', () => {
it('should able to get empty result', async () => {
await etf.loadEtfInfo();

const result = (await etf.getEtfInfo()).filter((item) => item.a === '000');

expect(result).toEqual([]);
expect(result.length).toEqual(0);
});
});
});
});
32 changes: 0 additions & 32 deletions test/etf.test.js

This file was deleted.

Loading

0 comments on commit 3722c6c

Please sign in to comment.