Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automated tests #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test
on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test
5 changes: 5 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


yarn-path ".yarn/releases/yarn-1.22.22.cjs"
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"cicd:reversed": "yarn git:push:all:reversed && yarn release:draft && yarn release:publish",
"cicd": "yarn git:push:all && yarn release:draft && yarn release:publish",
"release:old:private": "CHANGELOG=$(sed -n \"/^## v$npm_package_version/,/^## /p\" CHANGELOG.md | sed '1d;$d') && gh release create v$npm_package_version --draft=false --title v$npm_package_version --notes \"$CHANGELOG\"",
"release:old:public": "CHANGELOG=$(sed -n \"/^## v$npm_package_version/,/^## /p\" CHANGELOG.md | sed '1d;$d') && gh release create v$npm_package_version --draft=false --title v$npm_package_version --notes \"$CHANGELOG\" --repo PeterBlenessy/stoqster-releases"
"release:old:public": "CHANGELOG=$(sed -n \"/^## v$npm_package_version/,/^## /p\" CHANGELOG.md | sed '1d;$d') && gh release create v$npm_package_version --draft=false --title v$npm_package_version --notes \"$CHANGELOG\" --repo PeterBlenessy/stoqster-releases",
"test": "jest"
},
"dependencies": {
"@intlify/unplugin-vue-i18n": "^4.0.0",
Expand All @@ -37,7 +38,8 @@
"@tauri-apps/cli": "^1.6.0",
"@vitejs/plugin-vue": "^5.0.5",
"sass": "^1.77.7",
"vite": "^5.3.3"
"vite": "^5.3.3",
"jest": "^29.0.0"
},
"browserslist": [
"last 10 Chrome versions",
Expand Down
42 changes: 42 additions & 0 deletions src/api/fiAPI.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { fiFunds, fiDownload, funds, fundHoldings } from './fiAPI';
import { ResponseType } from "@tauri-apps/api/http";

describe('fiAPI', () => {
test('fiFunds API should have correct URL and options', () => {
expect(fiFunds.url).toBe('https://www.fi.se/sv/vara-register/fondinnehav-per-kvartal/');
expect(fiFunds.options.method).toBe('get');
expect(fiFunds.options.responseType).toBe(ResponseType.Text);
});

test('fiDownload API should have correct URL and options', () => {
expect(fiDownload.url).toBe('https://www.fi.se');
expect(fiDownload.options.method).toBe('get');
expect(fiDownload.options.responseType).toBe('arraybuffer');
expect(fiDownload.options.headers).toEqual({
'Accept': 'application/zip',
'Content-Type': 'application/zip'
});
});

test('funds object should have correct properties', () => {
expect(funds.title).toBe('FI: Information om fonder och innehav');
expect(funds.localForageConfig.storeName).toBe('fi-funds');
expect(funds.fields).toEqual([
'Aktiv_risk',
'FinansiellaInstrument/FinansielltInstrument',
'Fond_ISIN-kod', 'Fond_institutnummer', 'Fond_namn', 'Fondförmögenhet',
'Förvaltningsavgift/UtanAndelsklasser/Förvaltningsavgift_fast',
'Jämförelseindex/Jämförelseindex',
'Likvida_medel', 'Standardavvikelse_24_månader', 'Övriga_tillgångar_och_skulder'
]);
});

test('fundHoldings object should have correct properties', () => {
expect(fundHoldings.title).toBe('Fondens innehav');
expect(fundHoldings.localForageConfig.storeName).toBe('fi-funds-holdings');
expect(fundHoldings.fields).toEqual([
'Andel_av_fondförmögenhet_instrument', 'Antal', 'Bransch/Bransch_namn_instrument', 'Bransch/Branschkod_instrument', 'ISIN-kod_instrument', 'Instrumentnamn', 'Kurs_som_använts_vid_värdering_av_instrumentet',
'Landkod_Emittent', 'Marknadsvärde_instrument', 'Nominellt_belopp', 'Tillgångsslag_enligt_LVF_5_kap', 'Valuta', 'Valutakurs_instrument'
]);
});
});
62 changes: 62 additions & 0 deletions src/api/ibindexAPI.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { ibindex, ibiRequestOptions } from './ibindexAPI';
import { ResponseType } from "@tauri-apps/api/http";

describe('ibindexAPI', () => {
test('ibiRequestOptions should return correct URL and options for getCompanies', () => {
const { url, options } = ibiRequestOptions('getCompanies');
expect(url).toBe('https://ibindex.se/ibi//index/getProducts.req');
expect(options.method).toBe('post');
expect(options.responseType).toBe(ResponseType.JSON);
expect(options.headers).toEqual({
'Content-Type': 'application/json;charset=UTF-8'
});
});

test('ibindex.getCompanies should have correct properties', () => {
expect(ibindex.getCompanies.title).toBe('Ibindex: Rapporterade och beräknade värden');
expect(ibindex.getCompanies.url).toBe('https://ibindex.se/ibi//index/getProducts.req');
expect(ibindex.getCompanies.fields).toEqual([
'productName', 'product', 'netAssetValue', 'netAssetValueCalculated', 'netAssetValueCalculatedRebatePremium', 'netAssetValueRebatePremium', 'netAssetValueChangeDate', 'price', 'previousPrice', 'priceChange'
]);
});

test('ibindex.getWeights should have correct properties', () => {
expect(ibindex.getWeights.title).toBe('Ibindex: Index- och marknadsvikt');
expect(ibindex.getWeights.url).toBe('https://ibindex.se/ibi//companies/getCompanies.req');
expect(ibindex.getWeights.fields).toEqual([
'product', 'productName', 'indexWeight', 'marketWeight'
]);
});

test('ibindex.getTrends should have correct properties', () => {
expect(ibindex.getTrends.title).toBe('Ibindex: Trender - pris och substansvärde');
expect(ibindex.getTrends.url).toBe('https://ibindex.se/ibi//index/getTrends.req');
expect(ibindex.getTrends.fields).toEqual([
"product", "productName", "price", "navCalculatedPerShare", "thirtyDaysPriceChange", "sixMonthPriceChange", "oneYearPriceChange", "threeYearPriceChange", "fiveYearPriceChange", "thirtyDaysNavChange", "sixMonthNavChange", "oneYearNavChange", "threeYearNavChange", "fiveYearNavChange"
]);
});

test('ibindex.getRebatePremiums should have correct properties', () => {
expect(ibindex.getRebatePremiums.title).toBe('Rabatt & Premium över tid');
expect(ibindex.getRebatePremiums.url).toBe('https://ibindex.se/ibi//company/getRebatePremiums.req');
expect(ibindex.getRebatePremiums.fields).toEqual([
'rebatePremium', 'calculatedRebatePremium', 'rebatePremiumMax', 'rebatePremiumMin', 'rebatePremiumAverage', 'calculatedRebatePremiumMax', 'calculatedRebatePremiumMin', 'calculatedRebatePremiumAverage', 'label'
]);
});

test('ibindex.getHoldings should have correct properties', () => {
expect(ibindex.getHoldings.title).toBe('Bolagets innehav');
expect(ibindex.getHoldings.url).toBe('https://ibindex.se/ibi//company/getHoldings.req');
expect(ibindex.getHoldings.fields).toEqual([
'holdingName', 'holdingProduct', 'holdingValue', 'holdingValuePrevious', 'listed'
]);
});

test('ibindex.getEvents should have correct properties', () => {
expect(ibindex.getEvents.title).toBe('Kalender');
expect(ibindex.getEvents.url).toBe('https://ibindex.se/ibi//company/getEvents.req');
expect(ibindex.getEvents.fields).toEqual([
'product', 'productName', 'eventDate', 'eventType', 'eventName', 'eventDetails'
]);
});
});