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
| dbSeeder.addFactory("user", "users", (data: any = {}): any => { | |
| return { | |
| id: faker.random.number(999999), | |
| first_name: faker.name.findName(), | |
| last_name: faker.namelName(), | |
| }; | |
| }); | |
| dbSeeder.addFactory("post", "posts", (data: any = {}): any => { | |
| return { | |
| id: faker.random.number(999999), |
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 KnexStorageWriter implements IStorageWriter { | |
| private knex: Knex; | |
| constructor(knex: Knex) { | |
| this.knex = knex; | |
| } | |
| insert = async (tableName: string, data: any, id: string = 'id') => { | |
| const [result] = await this.knex(tableName).insert(data, [id]); | |
| return { | |
| ...result, |
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 KnexStorageWriter implements IStorageWriter { | |
| private knex: Knex; | |
| constructor(knex: Knex) { | |
| this.knex = knex; | |
| } | |
| insert = async (tableName: string, data: any, id: string = 'id') => { | |
| const [result] = await this.knex(tableName).insert(data, [id]); | |
| return { | |
| ...result, |
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
| await knex("users").insert(DataGenerator.user({id: 2})); | |
| await knex("posts").insert(DataGenerator.post({id: 2, user_id: 2, title: "Title 2"})); |
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
| const DataGenerator = { | |
| post: (data = {}) => { | |
| return { | |
| id: faker.random.number(999999), | |
| user_id: faker.random.number(999999), | |
| title: faker.lorem.sentence(), | |
| body: faker.lorem.text(), | |
| ...data, | |
| }; | |
| } |
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
| const repo = new PostsRepo(knex); | |
| it("updates existing post", async () => { | |
| await knex("users").insert({ id: 1, first_name: "John", last_name: "doe" }); | |
| await knex("posts").insert({ id: 2, user_id: 1, title: "Post Title", body: "body"}); | |
| repo.updatePost(1, { title: "title 2" }); | |
| const [updatedPost] = await knex("posts").where({ id: 2 }); | |
| expect(updatedPost.title).toEqual("title 2"); | |
| }); |
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
| interface IProps { | |
| socialAuth: ISocialAuth; | |
| } | |
| export default class SocialLoginForm extends Component<IProps> { | |
| loginWithSocialAccount = (e: React.SyntheticEvent) => { | |
| const dataProvider = e.target.dataset.provider | |
| const { socialAuth } = this.props; | |
| socialAuth.login(dataProvider); | |
| }; |
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 socialAuth from "path/to/socialAuth"; | |
| export default class SocialLoginForm extends Component { | |
| loginWithSocialAccount = (e: React.SyntheticEvent) => { | |
| const dataProvider = e.target.dataset.provider | |
| socialAuth.login(dataProvider); | |
| }; | |
| render() { | |
| const { price } = this.state; |
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
| // let's add a container for all sagas | |
| import ISaga from "./ISaga"; | |
| import { all } from "redux-saga/effects"; | |
| export default class SagaContainer { | |
| private sagas: ISaga[] = []; | |
| addSaga(saga: ISaga) { | |
| this.sagas.push(saga); | |
| } |
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
| // ISaga.ts | |
| export default interface ISaga { | |
| register(): Iterable<any>; | |
| } | |
| export default class ProductUpdatePageSaga implements ISaga { | |
| private readonly backend: IBackendApi; | |
| private readonly history: History; | |
| constructor(backend: IBackendApi, history: History) { |