-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get tasotarkistus from the api through a reducer
- Loading branch information
1 parent
6fea815
commit 994d17a
Showing
14 changed files
with
278 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createAction } from "redux-actions"; | ||
import { FETCH_ACTION_STRING, NOT_FOUND_ACTION_STRING, RECEIVE_ACTION_STRING } from "./constants"; | ||
import { | ||
FetchOldDwellingsInHousingCompaniesPriceIndexAction, | ||
OldDwellingsInHousingCompaniesPriceIndex, | ||
OldDwellingsInHousingCompaniesPriceIndexNotFoundAction, | ||
ReceiveOldDwellingsInHousingCompaniesPriceIndexAction, | ||
} from "./types"; | ||
|
||
export const fetchOldDwellingsInHousingCompaniesPriceIndex = | ||
(): FetchOldDwellingsInHousingCompaniesPriceIndexAction => createAction(FETCH_ACTION_STRING)(); | ||
|
||
export const receiveOldDwellingsInHousingCompaniesPriceIndex = ( | ||
payload: OldDwellingsInHousingCompaniesPriceIndex, | ||
): ReceiveOldDwellingsInHousingCompaniesPriceIndexAction => | ||
createAction(RECEIVE_ACTION_STRING)(payload); | ||
|
||
export const notFound = (): OldDwellingsInHousingCompaniesPriceIndexNotFoundAction => | ||
createAction(NOT_FOUND_ACTION_STRING)(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const DEFAULT_OLD_DWELLINGS_IN_HOUSING_COMPANIES_PRICE_INDEX_ID = 1; | ||
|
||
// Action type strings | ||
export const FETCH_ACTION_STRING = "mvj/oldDwellingsInHousingCompaniesPriceIndex/FETCH"; | ||
export const RECEIVE_ACTION_STRING = "mvj/oldDwellingsInHousingCompaniesPriceIndex/RECEIVE"; | ||
export const NOT_FOUND_ACTION_STRING = "mvj/oldDwellingsInHousingCompaniesPriceIndex/NOT_FOUND"; |
87 changes: 87 additions & 0 deletions
87
...oldDwellingsInHousingCompaniesPriceIndex/oldDwellingsInHousingCompaniesPriceIndex.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { | ||
receiveOldDwellingsInHousingCompaniesPriceIndex, | ||
fetchOldDwellingsInHousingCompaniesPriceIndex, | ||
notFound, | ||
} from "./actions"; | ||
import oldDwellingsInHousingCompaniesPriceIndexReducer from "./reducer"; | ||
import type { | ||
OldDwellingsInHousingCompaniesPriceIndex, | ||
OldDwellingsInHousingCompaniesPriceIndexState, | ||
} from "./types"; | ||
const defaultState: OldDwellingsInHousingCompaniesPriceIndexState = { | ||
isFetching: false, | ||
latest: null, | ||
}; | ||
|
||
describe("oldDwellingsInHousingCompaniesPriceIndex", () => { | ||
describe("Reducer", () => { | ||
describe("oldDwellingsInHousingCompaniesPriceIndexReducer", () => { | ||
it("should update oldDwellingsInHousingCompaniesPriceIndex", () => { | ||
const dummy: OldDwellingsInHousingCompaniesPriceIndex = { | ||
point_figures: [ | ||
{ | ||
value: 97.4, | ||
year: 2023, | ||
region: "pks", | ||
comment: "", | ||
}, | ||
{ | ||
value: 105.7, | ||
year: 2022, | ||
region: "pks", | ||
comment: "", | ||
}, | ||
{ | ||
value: 105.6, | ||
year: 2021, | ||
region: "pks", | ||
comment: "", | ||
}, | ||
{ | ||
value: 100.0, | ||
year: 2020, | ||
region: "pks", | ||
comment: "", | ||
}, | ||
], | ||
created_at: "2024-11-14T15:12:50.310543+02:00", | ||
modified_at: "2024-12-08T18:05:37.983780+02:00", | ||
code: "ketj_P_QA_T", | ||
name: "Indeksi (2020=100)", | ||
comment: | ||
"Indeksi on suhdeluku, joka kuvaa jonkin muuttujan (esimerkiksi hinnan, määrän tai arvon) suhteellista muutosta perusjakson (esimerkiksi vuoden) suhteen. Kunkin ajankohdan indeksipisteluku ilmoittaa, kuinka monta prosenttia kyseisen ajankohdan tarkasteltava muuttuja on perusjakson arvosta tai määrästä. Perusjakson indeksipistelukujen keskiarvo on 100. Tilastossa julkaistavat hintaindeksit ovat laatuvakioituja ja niiden kehitys voi poiketa neliöhintojen kehityksestä.\r\n", | ||
source: "Tilastokeskus, osakeasuntojen hinnat", | ||
source_table_updated: "2024-05-03T08:00:00+03:00", | ||
source_table_label: | ||
"Vanhojen osakeasuntojen hintaindeksi (2020=100) ja kauppojen lukumäärät, vuositasolla muuttujina Vuosi, Alue ja Tiedot", | ||
url: "https://pxdata.stat.fi:443/PxWeb/api/v1/fi/StatFin/ashi/statfin_ashi_pxt_13mq.px", | ||
}; | ||
|
||
const newState = { ...defaultState, latest: dummy }; | ||
const state = oldDwellingsInHousingCompaniesPriceIndexReducer( | ||
{}, | ||
receiveOldDwellingsInHousingCompaniesPriceIndex(dummy), | ||
); | ||
expect(state).to.deep.equal(newState); | ||
}); | ||
it("should update isFetching flag to true when fetching vats", () => { | ||
const newState = { ...defaultState, isFetching: true }; | ||
const state = oldDwellingsInHousingCompaniesPriceIndexReducer( | ||
{}, | ||
fetchOldDwellingsInHousingCompaniesPriceIndex(), | ||
); | ||
expect(state).to.deep.equal(newState); | ||
}); | ||
it("should update isFetching flag to false by notFound", () => { | ||
const newState = { ...defaultState }; | ||
let state = oldDwellingsInHousingCompaniesPriceIndexReducer( | ||
{}, | ||
fetchOldDwellingsInHousingCompaniesPriceIndex(), | ||
); | ||
state = oldDwellingsInHousingCompaniesPriceIndexReducer(state, notFound()); | ||
expect(state).to.deep.equal(newState); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { combineReducers } from "redux"; | ||
import { handleActions } from "redux-actions"; | ||
import type { Reducer } from "@/types"; | ||
import { | ||
FETCH_ACTION_STRING, | ||
NOT_FOUND_ACTION_STRING, | ||
RECEIVE_ACTION_STRING, | ||
} from "./constants"; | ||
import { | ||
OldDwellingsInHousingCompaniesPriceIndex, | ||
ReceiveOldDwellingsInHousingCompaniesPriceIndexAction, | ||
} from "./types"; | ||
|
||
const isFetchingReducer: Reducer<boolean> = handleActions( | ||
{ | ||
[FETCH_ACTION_STRING]: () => true, | ||
[NOT_FOUND_ACTION_STRING]: () => false, | ||
[RECEIVE_ACTION_STRING]: () => false, | ||
}, | ||
false, | ||
); | ||
const latestReducer: Reducer<OldDwellingsInHousingCompaniesPriceIndex> = handleActions( | ||
{ | ||
[RECEIVE_ACTION_STRING]: ( | ||
state: OldDwellingsInHousingCompaniesPriceIndex, | ||
{ payload }: ReceiveOldDwellingsInHousingCompaniesPriceIndexAction, | ||
) => { | ||
return payload; | ||
}, | ||
}, | ||
null, | ||
); | ||
export default combineReducers<Record<string, any>, any>({ | ||
isFetching: isFetchingReducer, | ||
latest: latestReducer, | ||
}); |
Oops, something went wrong.