Ex6 fixes (#108)
* improve comments readability * fix name of function to clarify expectation * fix inaccurate expectation
This commit is contained in:
parent
f5babc5737
commit
e11c1b34c8
2 changed files with 25 additions and 17 deletions
|
@ -5,7 +5,7 @@ import {
|
||||||
getCapitalizedUserName,
|
getCapitalizedUserName,
|
||||||
getConcatenationOfTheBestFriendNameAndUserName,
|
getConcatenationOfTheBestFriendNameAndUserName,
|
||||||
getConcatenationOfTheTwoUserNames,
|
getConcatenationOfTheTwoUserNames,
|
||||||
getConcatenationOfUserNameAndYear,
|
getConcatenationOfUserNameAndCurrentYear,
|
||||||
} from './exo6';
|
} from './exo6';
|
||||||
|
|
||||||
describe('exo6', () => {
|
describe('exo6', () => {
|
||||||
|
@ -34,7 +34,7 @@ describe('exo6', () => {
|
||||||
|
|
||||||
const result = await usecase();
|
const result = await usecase();
|
||||||
|
|
||||||
expect(result).toEqual(either.right('robscott'));
|
expect(result).toEqual(either.right('RobScott'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the concatenation of the two capitalized user names based on the best friend relation', async () => {
|
it('should return the concatenation of the two capitalized user names based on the best friend relation', async () => {
|
||||||
|
@ -49,13 +49,13 @@ describe('exo6', () => {
|
||||||
|
|
||||||
const result = await usecase();
|
const result = await usecase();
|
||||||
|
|
||||||
expect(result).toEqual(either.right('robscott'));
|
expect(result).toEqual(either.right('RobScott'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the concatenation of the two capitalized user names based on the best friend relation', async () => {
|
it('should return the concatenation of the user name and the current year', async () => {
|
||||||
const timeservice = new Application.NodeTimeService.NodeTimeService();
|
const timeservice = new Application.NodeTimeService.NodeTimeService();
|
||||||
|
|
||||||
const usecase = getConcatenationOfUserNameAndYear({
|
const usecase = getConcatenationOfUserNameAndCurrentYear({
|
||||||
userIdOne: '1',
|
userIdOne: '1',
|
||||||
})({
|
})({
|
||||||
userRepository: new User.Repository.InMemoryUserRepository([
|
userRepository: new User.Repository.InMemoryUserRepository([
|
||||||
|
|
|
@ -6,7 +6,8 @@ import { unimplemented } from '../utils';
|
||||||
import { Application } from './application';
|
import { Application } from './application';
|
||||||
import { User } from './domain';
|
import { User } from './domain';
|
||||||
|
|
||||||
// In real world applications you will mostly manipulate `ReaderTaskEither` aka `rte` in the use-cases of the application.
|
// In real world applications you will mostly manipulate `ReaderTaskEither` aka
|
||||||
|
// `rte` in the use-cases of the application.
|
||||||
// `Reader` -> For dependency injection
|
// `Reader` -> For dependency injection
|
||||||
// `Task` -> For async operation
|
// `Task` -> For async operation
|
||||||
// `Either` -> For computations that may fail
|
// `Either` -> For computations that may fail
|
||||||
|
@ -18,8 +19,10 @@ import { User } from './domain';
|
||||||
// You will learn the usage of the most common in the following usecases.
|
// You will learn the usage of the most common in the following usecases.
|
||||||
|
|
||||||
// In the following usecase, you will learn the usage of `rte.map()`.
|
// In the following usecase, you will learn the usage of `rte.map()`.
|
||||||
// `rte.map()` allows you to perform an operation on the values stored in the current context.
|
// `rte.map()` allows you to perform an operation on the values stored in the
|
||||||
// In the following example, we need to fetch a user by its id and then we want to return its capitalized.
|
// current context. In the following example, we need to fetch a user by its id
|
||||||
|
// and then we want to return its capitalized.
|
||||||
|
|
||||||
|
|
||||||
export const getCapitalizedUserName: (args: {
|
export const getCapitalizedUserName: (args: {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
@ -29,11 +32,12 @@ export const getCapitalizedUserName: (args: {
|
||||||
string
|
string
|
||||||
> = unimplemented;
|
> = unimplemented;
|
||||||
|
|
||||||
// Sometimes you will need to get multiple data before performing an operation on them.
|
// Sometimes you will need to get multiple data before performing an operation
|
||||||
// In this case, it is very convenient to use the `Do` notation.
|
// on them. In this case, it is very convenient to use the `Do` notation.
|
||||||
//
|
//
|
||||||
// The `Do` notation allows you to enrich the context step-by-step by binding the result
|
// The `Do` notation allows you to enrich the context step-by-step by binding
|
||||||
// of an effect (in this case a RTE) to a named variable using `rte.apS` or `rte.apSW`.
|
// the result of an effect (in this case a RTE) to a named variable using
|
||||||
|
// `rte.apS` or `rte.apSW`.
|
||||||
//
|
//
|
||||||
// For example:
|
// For example:
|
||||||
// pipe(
|
// pipe(
|
||||||
|
@ -51,10 +55,14 @@ export const getConcatenationOfTheTwoUserNames: (args: {
|
||||||
string
|
string
|
||||||
> = unimplemented;
|
> = unimplemented;
|
||||||
|
|
||||||
// Sometimes, you will need to feed the current context with data that you can only retrieve after performing some operations.
|
// Sometimes, you will need to feed the current context with data that you can
|
||||||
// For example, if you want to fetch the best friend of a user you will have to fetch the first user and then fetch its bestfriend.
|
// only retrieve after performing some operations, in other words, operations
|
||||||
// In this case, we will use `rte.bindW()` to use data of the current context (the firstly fetched user)
|
// need to be sequential.
|
||||||
// to perform a second operation (fetch its bestfriend) and bind the return value to feed the context and use those data.
|
// For example, if you want to fetch the best friend of a user you will have to
|
||||||
|
// fetch the first user and then fetch its best friend.
|
||||||
|
// In this case, we will use `rte.bindW()` to use data of the current context
|
||||||
|
// (the firstly fetched user) to perform a second operation (fetch its best friend)
|
||||||
|
// and bind the return value to feed the context and use those data.
|
||||||
|
|
||||||
export const getConcatenationOfTheBestFriendNameAndUserName: (args: {
|
export const getConcatenationOfTheBestFriendNameAndUserName: (args: {
|
||||||
userIdOne: string;
|
userIdOne: string;
|
||||||
|
@ -68,7 +76,7 @@ export const getConcatenationOfTheBestFriendNameAndUserName: (args: {
|
||||||
// The challenge of this usecase is to use TimeService in the flow of our `rte`
|
// The challenge of this usecase is to use TimeService in the flow of our `rte`
|
||||||
type Dependencies = User.Repository.Access & Application.TimeService.Access;
|
type Dependencies = User.Repository.Access & Application.TimeService.Access;
|
||||||
|
|
||||||
export const getConcatenationOfUserNameAndYear: (args: {
|
export const getConcatenationOfUserNameAndCurrentYear: (args: {
|
||||||
userIdOne: string;
|
userIdOne: string;
|
||||||
}) => ReaderTaskEither<
|
}) => ReaderTaskEither<
|
||||||
Dependencies,
|
Dependencies,
|
||||||
|
|
Reference in a new issue