Skip to content

Commit

Permalink
fix: Rename actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Sep 29, 2023
1 parent 14b4b02 commit 1bb8006
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
24 changes: 12 additions & 12 deletions src/modules/worlds/actions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { WorldsWalletStats } from 'lib/api/worlds'
import {
FETCH_WALLET_WORLDS_STATS_FAILURE,
FETCH_WALLET_WORLDS_STATS_REQUEST,
FETCH_WALLET_WORLDS_STATS_SUCCESS,
fetchWalletWorldsStatsFailure,
fetchWalletWorldsStatsRequest,
fetchWalletWorldsStatsSuccess
FETCH_WORLDS_WALLET_STATS_FAILURE,
FETCH_WORLDS_WALLET_STATS_REQUEST,
FETCH_WORLDS_WALLET_STATS_SUCCESS,
fetchWorldsWalletStatsFailure,
fetchWorldsWalletStatsRequest,
fetchWorldsWalletStatsSuccess
} from './actions'

let address: string
Expand All @@ -16,8 +16,8 @@ beforeEach(() => {

describe('when creating the request action to fetch worlds stats for a wallet', () => {
it('should return the request action to fetch worlds stats for a wallet', () => {
expect(fetchWalletWorldsStatsRequest(address)).toEqual({
type: FETCH_WALLET_WORLDS_STATS_REQUEST,
expect(fetchWorldsWalletStatsRequest(address)).toEqual({
type: FETCH_WORLDS_WALLET_STATS_REQUEST,
payload: {
address
}
Expand All @@ -39,8 +39,8 @@ describe('when creating the success action to fetch worlds stats for a wallet',
})

it('should return the success action to fetch worlds stats for a wallet', () => {
expect(fetchWalletWorldsStatsSuccess(address, stats)).toEqual({
type: FETCH_WALLET_WORLDS_STATS_SUCCESS,
expect(fetchWorldsWalletStatsSuccess(address, stats)).toEqual({
type: FETCH_WORLDS_WALLET_STATS_SUCCESS,
payload: {
address,
stats
Expand All @@ -57,8 +57,8 @@ describe('when creating the failure action to fetch worlds stats for a wallet',
})

it('should return the failure action to fetch worlds stats for a wallet', () => {
expect(fetchWalletWorldsStatsFailure(address, error)).toEqual({
type: FETCH_WALLET_WORLDS_STATS_FAILURE,
expect(fetchWorldsWalletStatsFailure(address, error)).toEqual({
type: FETCH_WORLDS_WALLET_STATS_FAILURE,
payload: {
address,
error
Expand Down
24 changes: 12 additions & 12 deletions src/modules/worlds/actions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { action } from 'typesafe-actions'
import { WorldsWalletStats } from 'lib/api/worlds'

// Fetch Wallet Worlds Stats
export const FETCH_WALLET_WORLDS_STATS_REQUEST = '[Request] Fetch Wallet Worlds Stats'
export const FETCH_WALLET_WORLDS_STATS_SUCCESS = '[Success] Fetch Wallet Worlds Stats'
export const FETCH_WALLET_WORLDS_STATS_FAILURE = '[Failure] Fetch Wallet Worlds Stats'
// Fetch Worlds Wallet Stats
export const FETCH_WORLDS_WALLET_STATS_REQUEST = '[Request] Fetch Worlds Wallet Stats'
export const FETCH_WORLDS_WALLET_STATS_SUCCESS = '[Success] Fetch Worlds Wallet Stats'
export const FETCH_WORLDS_WALLET_STATS_FAILURE = '[Failure] Fetch Worlds Wallet Stats'

export const fetchWalletWorldsStatsRequest = (address: string) => action(FETCH_WALLET_WORLDS_STATS_REQUEST, { address })
export const fetchWalletWorldsStatsSuccess = (address: string, stats: WorldsWalletStats) =>
action(FETCH_WALLET_WORLDS_STATS_SUCCESS, { address, stats })
export const fetchWalletWorldsStatsFailure = (address: string, error: string) =>
action(FETCH_WALLET_WORLDS_STATS_FAILURE, { address, error })
export const fetchWorldsWalletStatsRequest = (address: string) => action(FETCH_WORLDS_WALLET_STATS_REQUEST, { address })
export const fetchWorldsWalletStatsSuccess = (address: string, stats: WorldsWalletStats) =>
action(FETCH_WORLDS_WALLET_STATS_SUCCESS, { address, stats })
export const fetchWorldsWalletStatsFailure = (address: string, error: string) =>
action(FETCH_WORLDS_WALLET_STATS_FAILURE, { address, error })

export type FetchWalletWorldsStatsRequestAction = ReturnType<typeof fetchWalletWorldsStatsRequest>
export type FetchWalletWorldsStatsSuccessAction = ReturnType<typeof fetchWalletWorldsStatsSuccess>
export type FetchWalletWorldsStatsFailureAction = ReturnType<typeof fetchWalletWorldsStatsFailure>
export type FetchWalletWorldsStatsRequestAction = ReturnType<typeof fetchWorldsWalletStatsRequest>
export type FetchWalletWorldsStatsSuccessAction = ReturnType<typeof fetchWorldsWalletStatsSuccess>
export type FetchWalletWorldsStatsFailureAction = ReturnType<typeof fetchWorldsWalletStatsFailure>
12 changes: 6 additions & 6 deletions src/modules/worlds/reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WorldsWalletStats } from 'lib/api/worlds'
import { fetchWalletWorldsStatsFailure, fetchWalletWorldsStatsRequest, fetchWalletWorldsStatsSuccess } from './actions'
import { fetchWorldsWalletStatsFailure, fetchWorldsWalletStatsRequest, fetchWorldsWalletStatsSuccess } from './actions'
import { INITIAL_STATE, WorldsState, worldsReducer } from './reducer'

let state: WorldsState
Expand All @@ -21,7 +21,7 @@ describe('when handling the action to fetch worlds stats for a wallet', () => {
})

it('should add the action to the loading state and remove the error', () => {
const action = fetchWalletWorldsStatsRequest(address)
const action = fetchWorldsWalletStatsRequest(address)

expect(worldsReducer(state, action)).toEqual({
...state,
Expand All @@ -36,11 +36,11 @@ describe('when handling the action to fetch worlds stats for a wallet', () => {

beforeEach(() => {
error = 'some error'
state.loading = [fetchWalletWorldsStatsRequest(address)]
state.loading = [fetchWorldsWalletStatsRequest(address)]
})

it('should remove the action from loading and set the error', () => {
const action = fetchWalletWorldsStatsFailure(address, error)
const action = fetchWorldsWalletStatsFailure(address, error)

expect(worldsReducer(state, action)).toEqual({
...state,
Expand All @@ -62,11 +62,11 @@ describe('when handling the action to fetch worlds stats for a wallet', () => {
wallet: address
}

state.loading = [fetchWalletWorldsStatsRequest(address)]
state.loading = [fetchWorldsWalletStatsRequest(address)]
})

it('should remove the action from loading and set the stats', () => {
const action = fetchWalletWorldsStatsSuccess(address, stats)
const action = fetchWorldsWalletStatsSuccess(address, stats)

expect(worldsReducer(state, action)).toEqual({
...state,
Expand Down
12 changes: 6 additions & 6 deletions src/modules/worlds/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
FetchWalletWorldsStatsRequestAction,
FetchWalletWorldsStatsFailureAction,
FetchWalletWorldsStatsSuccessAction,
FETCH_WALLET_WORLDS_STATS_REQUEST,
FETCH_WALLET_WORLDS_STATS_SUCCESS,
FETCH_WALLET_WORLDS_STATS_FAILURE
FETCH_WORLDS_WALLET_STATS_REQUEST,
FETCH_WORLDS_WALLET_STATS_SUCCESS,
FETCH_WORLDS_WALLET_STATS_FAILURE
} from './actions'
import { WorldsWalletStats } from 'lib/api/worlds'

Expand All @@ -31,14 +31,14 @@ export type WorldsReducerAction =

export function worldsReducer(state: WorldsState = INITIAL_STATE, action: WorldsReducerAction): WorldsState {
switch (action.type) {
case FETCH_WALLET_WORLDS_STATS_REQUEST: {
case FETCH_WORLDS_WALLET_STATS_REQUEST: {
return {
...state,
loading: loadingReducer(state.loading, action),
error: null
}
}
case FETCH_WALLET_WORLDS_STATS_FAILURE: {
case FETCH_WORLDS_WALLET_STATS_FAILURE: {
const { error } = action.payload

return {
Expand All @@ -47,7 +47,7 @@ export function worldsReducer(state: WorldsState = INITIAL_STATE, action: Worlds
error
}
}
case FETCH_WALLET_WORLDS_STATS_SUCCESS: {
case FETCH_WORLDS_WALLET_STATS_SUCCESS: {
const { address, stats } = action.payload

return {
Expand Down
16 changes: 8 additions & 8 deletions src/modules/worlds/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expectSaga } from 'redux-saga-test-plan'
import { worldsSaga } from './sagas'
import { call } from 'redux-saga/effects'
import { WorldsWalletStats, content } from 'lib/api/worlds'
import { fetchWalletWorldsStatsFailure, fetchWalletWorldsStatsRequest, fetchWalletWorldsStatsSuccess } from './actions'
import { fetchWorldsWalletStatsFailure, fetchWorldsWalletStatsRequest, fetchWorldsWalletStatsSuccess } from './actions'
import { throwError } from 'redux-saga-test-plan/providers'

describe('when handling the request action to fetch worlds stats for a wallet', () => {
Expand All @@ -22,18 +22,18 @@ describe('when handling the request action to fetch worlds stats for a wallet',
it('should put the failure action with the request action address and the error message', () => {
return expectSaga(worldsSaga)
.provide([[call([content, content.fetchWalletStats], address), throwError(error)]])
.put(fetchWalletWorldsStatsFailure(address, error.message))
.dispatch(fetchWalletWorldsStatsRequest(address))
.put(fetchWorldsWalletStatsFailure(address, error.message))
.dispatch(fetchWorldsWalletStatsRequest(address))
.silentRun()
})
})

describe('when the worlds api request return null', () => {
it('should put teh failure action with the request action address and the error message', () => {
it('should put the failure action with the request action address and the error message', () => {
return expectSaga(worldsSaga)
.provide([[call([content, content.fetchWalletStats], address), null]])
.put(fetchWalletWorldsStatsFailure(address, 'Could not fetch wallet stats'))
.dispatch(fetchWalletWorldsStatsRequest(address))
.put(fetchWorldsWalletStatsFailure(address, 'Could not fetch wallet stats'))
.dispatch(fetchWorldsWalletStatsRequest(address))
.silentRun()
})
})
Expand All @@ -54,8 +54,8 @@ describe('when handling the request action to fetch worlds stats for a wallet',
it('should put the success action with the request action address and the stats', () => {
return expectSaga(worldsSaga)
.provide([[call([content, content.fetchWalletStats], address), stats]])
.put(fetchWalletWorldsStatsSuccess(address, stats))
.dispatch(fetchWalletWorldsStatsRequest(address))
.put(fetchWorldsWalletStatsSuccess(address, stats))
.dispatch(fetchWorldsWalletStatsRequest(address))
.silentRun()
})
})
Expand Down
14 changes: 7 additions & 7 deletions src/modules/worlds/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { call, put, takeEvery } from 'redux-saga/effects'
import { WorldsWalletStats, content as WorldsAPIContent } from 'lib/api/worlds'
import {
FETCH_WALLET_WORLDS_STATS_REQUEST,
FETCH_WORLDS_WALLET_STATS_REQUEST,
FetchWalletWorldsStatsRequestAction,
fetchWalletWorldsStatsFailure,
fetchWalletWorldsStatsSuccess
fetchWorldsWalletStatsFailure,
fetchWorldsWalletStatsSuccess
} from './actions'

export function* worldsSaga() {
yield takeEvery(FETCH_WALLET_WORLDS_STATS_REQUEST, handleFetchWalletWorldsStatsRequest)
yield takeEvery(FETCH_WORLDS_WALLET_STATS_REQUEST, handlefetchWorldsWalletStatsRequest)
}

function* handleFetchWalletWorldsStatsRequest(action: FetchWalletWorldsStatsRequestAction) {
function* handlefetchWorldsWalletStatsRequest(action: FetchWalletWorldsStatsRequestAction) {
const { address } = action.payload

try {
Expand All @@ -21,8 +21,8 @@ function* handleFetchWalletWorldsStatsRequest(action: FetchWalletWorldsStatsRequ
throw new Error('Could not fetch wallet stats')
}

yield put(fetchWalletWorldsStatsSuccess(address, stats))
yield put(fetchWorldsWalletStatsSuccess(address, stats))
} catch (e) {
yield put(fetchWalletWorldsStatsFailure(address, e.message))
yield put(fetchWorldsWalletStatsFailure(address, e.message))
}
}

0 comments on commit 1bb8006

Please sign in to comment.