This file contains hidden or 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
import { MessageService } from "../src/MessageService"; | |
import { UserServiceMocks } from "../@mocks/mockshot-example/UserService"; | |
describe("MessageService", () => { | |
const getUserResult = UserServiceMocks.getUser("success"); | |
const userService = { | |
getUser: ()=>getUserResult | |
} |
This file contains hidden or 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
import { UserService } from "./UserService"; | |
export class MessageService { | |
constructor(private readonly userService: UserService){} | |
async prepareMessage(text: string, userId: string) { | |
const user = await this.userService.getUser(userId); | |
return { | |
to: user.email, |
This file contains hidden or 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
export class UserServiceMocks { | |
static getUser(mock: "success"): any { | |
switch (mock) { | |
case "success": | |
return { | |
"email": "[email protected]", | |
"id": "abc", | |
"name": "Some Name" | |
} | |
default: |
This file contains hidden or 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
export interface IUser { | |
id: string; | |
name: string; | |
email: string; | |
} | |
export class UserService { | |
constructor(private readonly db){} |
This file contains hidden or 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
import { UserService } from "../src/UserService"; | |
describe("UserService", () => { | |
// fake database service | |
const db = { | |
findOneById: async (id) => { | |
const name = "Some Name"; | |
const email = "[email protected]"; | |
return { |
This file contains hidden or 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
/** | |
* Create app component (no container needed so it just mounts the page) | |
*/ | |
function SongsApp() { | |
return <SongsPage />; | |
} | |
/** | |
* Page component (no props so fetch song list with useSongList hook) |
This file contains hidden or 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
/** | |
* Create redux container | |
*/ | |
function mapDispatchToProps(dispatch) { | |
return bindActionCreators( | |
{ | |
fetchSongs: SongActions.fetchAll, | |
onDownload: SongActions.download | |
}, |