From c303e0cad7bde53f7ec791f65d4580aa482c7c2a Mon Sep 17 00:00:00 2001 From: Alex Mitchell Date: Wed, 28 Jun 2023 18:43:24 +0100 Subject: [PATCH 1/7] Update instructions --- .../fruit-picker/.docs/instructions.md | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/exercises/concept/fruit-picker/.docs/instructions.md b/exercises/concept/fruit-picker/.docs/instructions.md index 9c41e710c7..13a574b32b 100644 --- a/exercises/concept/fruit-picker/.docs/instructions.md +++ b/exercises/concept/fruit-picker/.docs/instructions.md @@ -2,27 +2,29 @@ You are creating a new online portal for your patrons to order their fruit fresh from the grocer. The grocer has an API that you can use to see if they have the inventory desired by your customers. You need to create a small library of functions for interacting with the grocer's API. -## 1. Create a callback to be called when the order is successful +## 1. Let your customer know that their order was successful -Write a callback function called `onSuccess` to be called when the order is successful. It should invoke the imported `notify` function passing a success message to it. +The portal should notify your customer if their order was successful. Define the `onSuccess` callback function that will be called if the order was successful because the grocer _has_ the fruit in stock. This function should invoke the imported `notify` function, passing `{ message: 'SUCCESS' }` to let your customer know that their order was successful. ```javascript onSuccess(); // => `notify` called with `{ message: 'SUCCESS' }` ``` -## 2. Create a callback to be called when the order fails with an error +## 2. Let your customer know that their order was unsuccessful -Write a callback function called `onError` to be called when the order encounters an error. It should invoke the imported `notify` function passing an error message to it. +The portal should notify your customer if their order was unsuccessful. Define the `onError` callback function that will be called if the order was unsuccessful because the grocer _does not have_ the fruit in stock or there was an error. This function should invoke the imported `notify` function, passing `{ message: 'ERROR' }` to let your customer know that their order was unsuccessful. ```javascript onError(); // => `notify` called with `{ message: 'ERROR' }` ``` -## 3. Create a wrapper to wrap the external api function +## 3. Create an API wrapper to wrap the grocer's API order function -The grocer's API provides a function to order from their inventory called `order`. It receives three arguments: a _query_, a _callback_ function to be invoked when the order is successful, and a _callback_ function to be invoked when the order encounters an error. You decide to wrap the api function call in a newly defined function `orderFromGrocer` to insulate your codebase from external changes. Your function should forward the arguments (which match the provided api function) to the api function. +Fruit orders are placed through the grocer's API via the provided `order` function. This function receives three arguments: a _query_, containing the `variety` and `quantity` of fruit requested, a _callback_ function to be invoked when the order is successful, and a _callback_ function to be invoked when the order encounters an error. + +You want to insulate your codebase from potential external changes and decide to wrap the call to the `order` function inside a new function named `orderFromGrocer`. Implement the `orderFromGrocer` function that attempts to place an order via a call to the grocer's API `order` function, making sure to forward the arguments passed into `orderFromGrocer` to the API call. The query takes the form of an _object_: @@ -42,11 +44,11 @@ orderFromGrocer( // => `order` was called with the query and the callbacks ``` -## 4. Create a convenient short function +## 4. Create a convenient helper function to place orders -You find that you are calling this function from many different places with the same functions. Seeing an opportunity to refactor your code, you want to create a function where you can supply the variety and quantity to order as arguments. +Your customers are now able to place fruit orders via your portal, however, you notice that you are invoking the `orderFromGrocer` function in many different places across your codebase, each time having to pass in a `query` and the 2 `callback` functions as arguments. Seeing an opportunity to refactor your code, you think it would be simpler if you could place an order by just passing the `variety` and `quanity` of fruit required. Define the `postOrder` helper function that takes `variety` and `quantity` as arguments and attempts to place an order with the grocer. ```javascript postOrder('peach', 100); -// => order submitted for 100 peaches +// => order placed for 100 peaches ``` From 06a95c57a7eee84f3432381f5c41226c35c8a0f9 Mon Sep 17 00:00:00 2001 From: Alex Mitchell Date: Wed, 28 Jun 2023 18:43:50 +0100 Subject: [PATCH 2/7] Update test case description --- exercises/concept/fruit-picker/fruit-picker.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/fruit-picker/fruit-picker.spec.js b/exercises/concept/fruit-picker/fruit-picker.spec.js index f920705511..4630fb5f7f 100644 --- a/exercises/concept/fruit-picker/fruit-picker.spec.js +++ b/exercises/concept/fruit-picker/fruit-picker.spec.js @@ -33,7 +33,7 @@ describe('task 2', () => { }); describe('task 3', () => { - test('order from grocer passes callback function arguments forward', () => { + test('orderFromGrocer passes query and callback function arguments forward', () => { const query = { variety: 'apple', quantity: 10 }; orderFromGrocer(query, onSuccess, onError); expect(order).toHaveBeenCalledTimes(1); From 09b492f8489b10130251a59f2204a11f4647a953 Mon Sep 17 00:00:00 2001 From: Alex Mitchell <43811589+alexmitchelldev@users.noreply.github.com> Date: Thu, 16 May 2024 03:31:03 -0500 Subject: [PATCH 3/7] Update exercises/concept/fruit-picker/.docs/instructions.md Co-authored-by: Erik Schierboom --- exercises/concept/fruit-picker/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/fruit-picker/.docs/instructions.md b/exercises/concept/fruit-picker/.docs/instructions.md index 13a574b32b..f291e39007 100644 --- a/exercises/concept/fruit-picker/.docs/instructions.md +++ b/exercises/concept/fruit-picker/.docs/instructions.md @@ -44,7 +44,7 @@ orderFromGrocer( // => `order` was called with the query and the callbacks ``` -## 4. Create a convenient helper function to place orders +## 4. Simplify handling placed orders Your customers are now able to place fruit orders via your portal, however, you notice that you are invoking the `orderFromGrocer` function in many different places across your codebase, each time having to pass in a `query` and the 2 `callback` functions as arguments. Seeing an opportunity to refactor your code, you think it would be simpler if you could place an order by just passing the `variety` and `quanity` of fruit required. Define the `postOrder` helper function that takes `variety` and `quantity` as arguments and attempts to place an order with the grocer. From fd12ac3430654f68cdf8733670dc6683aa94e67c Mon Sep 17 00:00:00 2001 From: Alex Mitchell <43811589+alexmitchelldev@users.noreply.github.com> Date: Thu, 16 May 2024 03:31:11 -0500 Subject: [PATCH 4/7] Update exercises/concept/fruit-picker/.docs/instructions.md Co-authored-by: Erik Schierboom --- exercises/concept/fruit-picker/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/fruit-picker/.docs/instructions.md b/exercises/concept/fruit-picker/.docs/instructions.md index f291e39007..b81f9acb23 100644 --- a/exercises/concept/fruit-picker/.docs/instructions.md +++ b/exercises/concept/fruit-picker/.docs/instructions.md @@ -46,7 +46,7 @@ orderFromGrocer( ## 4. Simplify handling placed orders -Your customers are now able to place fruit orders via your portal, however, you notice that you are invoking the `orderFromGrocer` function in many different places across your codebase, each time having to pass in a `query` and the 2 `callback` functions as arguments. Seeing an opportunity to refactor your code, you think it would be simpler if you could place an order by just passing the `variety` and `quanity` of fruit required. Define the `postOrder` helper function that takes `variety` and `quantity` as arguments and attempts to place an order with the grocer. +Your customers are now able to place fruit orders via your portal, however, you notice that you are invoking the `orderFromGrocer` function in many different places across your codebase, each time having to pass in a `query` and the two `callback` functions as arguments. Seeing an opportunity to refactor your code, you think it would be simpler if you could place an order by just passing the `variety` and `quantity` of fruit required. Define the `postOrder` helper function that takes `variety` and `quantity` as arguments and attempts to place an order with the grocer. ```javascript postOrder('peach', 100); From 37394b9b27489458ea703c87ce7e23966da5ab3f Mon Sep 17 00:00:00 2001 From: Alex Mitchell <43811589+alexmitchelldev@users.noreply.github.com> Date: Thu, 16 May 2024 03:31:16 -0500 Subject: [PATCH 5/7] Update exercises/concept/fruit-picker/.docs/instructions.md Co-authored-by: Erik Schierboom --- exercises/concept/fruit-picker/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/fruit-picker/.docs/instructions.md b/exercises/concept/fruit-picker/.docs/instructions.md index b81f9acb23..043e860d49 100644 --- a/exercises/concept/fruit-picker/.docs/instructions.md +++ b/exercises/concept/fruit-picker/.docs/instructions.md @@ -2,7 +2,7 @@ You are creating a new online portal for your patrons to order their fruit fresh from the grocer. The grocer has an API that you can use to see if they have the inventory desired by your customers. You need to create a small library of functions for interacting with the grocer's API. -## 1. Let your customer know that their order was successful +## 1. Notify your customer when their order was successful The portal should notify your customer if their order was successful. Define the `onSuccess` callback function that will be called if the order was successful because the grocer _has_ the fruit in stock. This function should invoke the imported `notify` function, passing `{ message: 'SUCCESS' }` to let your customer know that their order was successful. From 37c0b237d4287690f1e8d46794bbe080967adcb9 Mon Sep 17 00:00:00 2001 From: Alex Mitchell <43811589+alexmitchelldev@users.noreply.github.com> Date: Thu, 16 May 2024 03:31:22 -0500 Subject: [PATCH 6/7] Update exercises/concept/fruit-picker/.docs/instructions.md Co-authored-by: Erik Schierboom --- exercises/concept/fruit-picker/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/fruit-picker/.docs/instructions.md b/exercises/concept/fruit-picker/.docs/instructions.md index 043e860d49..7cd415d94b 100644 --- a/exercises/concept/fruit-picker/.docs/instructions.md +++ b/exercises/concept/fruit-picker/.docs/instructions.md @@ -11,7 +11,7 @@ onSuccess(); // => `notify` called with `{ message: 'SUCCESS' }` ``` -## 2. Let your customer know that their order was unsuccessful +## 2. Notify your customer when their order was unsuccessful The portal should notify your customer if their order was unsuccessful. Define the `onError` callback function that will be called if the order was unsuccessful because the grocer _does not have_ the fruit in stock or there was an error. This function should invoke the imported `notify` function, passing `{ message: 'ERROR' }` to let your customer know that their order was unsuccessful. From 2706b903d2986d3a3d9a55ea72860020b6fdf148 Mon Sep 17 00:00:00 2001 From: Alex Mitchell <43811589+alexmitchelldev@users.noreply.github.com> Date: Thu, 16 May 2024 03:31:28 -0500 Subject: [PATCH 7/7] Update exercises/concept/fruit-picker/.docs/instructions.md Co-authored-by: Erik Schierboom --- exercises/concept/fruit-picker/.docs/instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/fruit-picker/.docs/instructions.md b/exercises/concept/fruit-picker/.docs/instructions.md index 7cd415d94b..7ad591761a 100644 --- a/exercises/concept/fruit-picker/.docs/instructions.md +++ b/exercises/concept/fruit-picker/.docs/instructions.md @@ -4,7 +4,7 @@ You are creating a new online portal for your patrons to order their fruit fresh ## 1. Notify your customer when their order was successful -The portal should notify your customer if their order was successful. Define the `onSuccess` callback function that will be called if the order was successful because the grocer _has_ the fruit in stock. This function should invoke the imported `notify` function, passing `{ message: 'SUCCESS' }` to let your customer know that their order was successful. +The portal should notify your customer if their order was successful. Define the `onSuccess` callback function that will be called if the order was successful due to the grocer having enough fruit in stock. This function should invoke the imported `notify` function, passing `{ message: 'SUCCESS' }` to let your customer know that their order was successful. ```javascript onSuccess();