-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8db570
commit 8d62615
Showing
16 changed files
with
187 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ module.exports = { | |
globals: { | ||
__IS_DEV__: true, | ||
__API__: true, | ||
__PROJECT__: true, | ||
}, | ||
overrides: [ | ||
{ | ||
|
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
37 changes: 37 additions & 0 deletions
37
src/entities/Profile/model/services/fetchProfileData/fetchProfileData.test.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,37 @@ | ||
import { TestAsyncFunc } from 'shared/lib/tests/TestAsyncFunc/TestAsyncFunc'; | ||
import { fetchProfileData } from './fetchProfileData'; | ||
import { Profile } from '../../types/profile'; | ||
|
||
jest.mock('axios'); | ||
|
||
const profileData: Profile = { | ||
age: 99, | ||
city: 'Any city', | ||
country: 'Any country', | ||
email: 'Any email', | ||
firstName: 'Any firstName', | ||
secondName: 'Any secondName', | ||
username: 'username', | ||
}; | ||
|
||
describe('fetchProfileData.test', () => { | ||
test('success', async () => { | ||
const thunk = new TestAsyncFunc(fetchProfileData); | ||
thunk.api.get.mockReturnValue(Promise.resolve({ data: profileData })); | ||
|
||
const result = await thunk.callThunc(); | ||
|
||
expect(thunk.api.get).toHaveBeenCalled(); | ||
expect(result.meta.requestStatus).toBe('fulfilled'); | ||
expect(result.payload).toBe(profileData); | ||
}); | ||
|
||
test('error', async () => { | ||
const thunk = new TestAsyncFunc(fetchProfileData); | ||
thunk.api.get.mockReturnValue(Promise.resolve({ status: 403 })); | ||
|
||
const result = await thunk.callThunc(); | ||
|
||
expect(result.meta.requestStatus).toBe('rejected'); | ||
}); | ||
}); |
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
76 changes: 76 additions & 0 deletions
76
src/entities/Profile/model/services/updateProfileData/updateProfileData.test.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,76 @@ | ||
import { TestAsyncFunc } from 'shared/lib/tests/TestAsyncFunc/TestAsyncFunc'; | ||
import { updateProfileData } from './updateProfileData'; | ||
import { Profile, ValidateProfileError } from '../../types/profile'; | ||
|
||
jest.mock('axios'); | ||
|
||
const profileData: Profile = { | ||
age: 99, | ||
city: 'Any city', | ||
country: 'Any country', | ||
email: 'Any email', | ||
firstName: 'Any firstName', | ||
secondName: 'Any secondName', | ||
username: 'username', | ||
}; | ||
|
||
describe('fetchProfileData.test', () => { | ||
test('success', async () => { | ||
const thunk = new TestAsyncFunc( | ||
updateProfileData, | ||
{ | ||
profile: { | ||
form: profileData, | ||
}, | ||
}, | ||
); | ||
thunk.api.put.mockReturnValue(Promise.resolve({ data: profileData })); | ||
|
||
const result = await thunk.callThunc(); | ||
|
||
expect(thunk.api.put).toHaveBeenCalled(); | ||
expect(result.meta.requestStatus).toBe('fulfilled'); | ||
expect(result.payload).toBe(profileData); | ||
}); | ||
|
||
test('error', async () => { | ||
const thunk = new TestAsyncFunc( | ||
updateProfileData, | ||
{ | ||
profile: { | ||
form: profileData, | ||
}, | ||
}, | ||
); | ||
thunk.api.put.mockReturnValue(Promise.resolve({ status: 403 })); | ||
|
||
const result = await thunk.callThunc(); | ||
|
||
expect(result.meta.requestStatus).toBe('rejected'); | ||
expect(result.payload).toEqual([ | ||
ValidateProfileError.SERVER_ERROR, | ||
]); | ||
}); | ||
|
||
test('validate error', async () => { | ||
const thunk = new TestAsyncFunc( | ||
updateProfileData, | ||
{ | ||
profile: { | ||
form: { | ||
...profileData, | ||
age: undefined, | ||
}, | ||
}, | ||
}, | ||
); | ||
thunk.api.put.mockReturnValue(Promise.resolve({ status: 403 })); | ||
|
||
const result = await thunk.callThunc(); | ||
|
||
expect(result.meta.requestStatus).toBe('rejected'); | ||
expect(result.payload).toEqual([ | ||
ValidateProfileError.INCORRECT_AGE, | ||
]); | ||
}); | ||
}); |
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
49 changes: 49 additions & 0 deletions
49
src/entities/Profile/model/services/validateProfileData/validateProfileData.test.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,49 @@ | ||
import { validateProfileData } from './validateProfileData'; | ||
import { Profile, ValidateProfileError } from '../../types/profile'; | ||
|
||
jest.mock('axios'); | ||
|
||
const profileData: Profile = { | ||
age: 99, | ||
city: 'Any city', | ||
country: 'Any country', | ||
email: 'Any email', | ||
firstName: 'Any firstName', | ||
secondName: 'Any secondName', | ||
username: 'username', | ||
}; | ||
|
||
describe('validateProfileData.test', () => { | ||
test('success', async () => { | ||
const result = validateProfileData(profileData); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
test('without secondname', async () => { | ||
const result = validateProfileData({ | ||
...profileData, | ||
secondName: '', | ||
}); | ||
|
||
expect(result).toEqual([ValidateProfileError.INCORRECT_USER_DATA]); | ||
}); | ||
|
||
test('without age', async () => { | ||
const result = validateProfileData({ | ||
...profileData, | ||
age: undefined, | ||
}); | ||
|
||
expect(result).toEqual([ValidateProfileError.INCORRECT_AGE]); | ||
}); | ||
|
||
test('with nothing', async () => { | ||
const result = validateProfileData({}); | ||
expect(result).toEqual([ | ||
ValidateProfileError.INCORRECT_USER_DATA, | ||
ValidateProfileError.INCORRECT_COUNTRY, | ||
ValidateProfileError.INCORRECT_AGE, | ||
]); | ||
}); | ||
}); |
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 @@ | ||
export const isFrontend = __PROJECT__ === 'frontend'; |
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 @@ | ||
export const isJest = __PROJECT__ === 'jest'; |
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 @@ | ||
export const isStorybook = __PROJECT__ === 'storybook'; |
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ export default (env: BuildEnv) => { | |
isDev, | ||
port, | ||
apiUrl, | ||
project: 'frontend', | ||
}); | ||
|
||
return config; | ||
|