Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Masai Full-Stack Engineer (… 600 minutes

This test has been locked by aby.antony@masaischool.com.

Question - 1
NodeJS: Kanban Board API

Implement a REST service that exposes the /boards endpoint.

Each product is a JSON entry with the following keys:


id : The unique reminder ID. (Integer)
title : The title of the TODO item. (String)
stage : The current stage of the item (Integer)

Here is an example of a reminder JSON object:

{
"id": 2,
"stage": 1,
"title": "Create a new project"
}

The model implementation is provided and is read-only.

It should allow for managing the collection of items in a Kanban Board in the current stage in the following way:

POST request to /boards :


creates a new item in the board
expects a JSON item object without the id and stage property as the body payload. You can assume that the given object is always valid.
adds the given object containing the item to the board and assigns a unique integer id to it. The first created item must have an id of 1, the second one,
2, and so on.
Each newly created item should have a stage of 1.
You can assume that the stage property will never be passed.
The response code is 201, and the response body is the created kanban board item object.

PUT request to /boards/:id


accepts the stage property containing the new stage as the body payload
updates the stage of the item for the passed item id
If the stage value passed is not 1,2, or 3, return the status code 400 with no requirement on the response body.
If the stage value is 1, 2 or 3, the response code is 200, with the updated item as the response body.
You can assume that the passed item ID always exists.

You should complete the given project so that it passes all the test cases when running the provided unit tests. The project by default supports the use of
the SQLite3 database.

Example requests and responses

POST request to / boards


Request body:

1/10
{
"title": "Create a new project"
}

The response code is 201, and when converted to JSON, the response body is:

{
"id": 1,
"stage": 1,
"title": "Create a new project"
}

This adds a new object to the collection with the given properties, id 1, with the stage set to 1.

PUT request to /boards/1


Request body:

{
"stage": 2
}

The response code is 200, the stage of item 1 has been updated to 2, and the updated item object is sent in the response body:

{
"id": 1,
"stage": 2,
"title": "Create a new project"
}

PUT request to /boards/1


Request body:

{
"stage": 4
}

The response code is 400 with no requirements for the response body.

Question - 2
React: Autocorrection App

Create a basic autocorrection application per the requirements below. The finished application must pass all of the unit tests.

Complete the implementation of src/components/AutocorrectTextarea.js according to the following requirements:

2/10
AutocorrectTextarea is a component that takes a corrections Object that maps strings to their corrections. For example, the object below denotes that
'really' is a correction for 'realy', and 'weird' is a correction of 'wierd':

const corrections = {
'realy': 'really',
'wierd': 'weird',
};

Assume that no value of the corrections object appears as the property in the corrections object.
AutocorrectTextarea renders a textarea element and lets users write text in it.
Assume that the text consists only of words separated by a single space character.
Once a space character is typed, the word preceding it is considered to be complete and must be autocorrected according to the corrections object if a
correction exists.

Initially, the file is filled with boilerplate code. Note the following:
The textarea element must have data-testid="textarea" .

Please note that the component has these data-testid attributes for test cases, and certain classes and ids for rendering purposes. You should not change
them.

Question - 3
JavaScript: Student Record Manipulation

In this challenge, the task is to implement a function manipulateStudentRecord that:


takes 4 arguments: an object literal obj, a string operation that is either "delete" or "edit", a string prop, and a string newValue.
returns a value depending on operation:
If operation is 'delete', then it returns a new object literal with the same properties and their values as obj has, except that if obj has
property prop, then this property must not be in the returned object literal. In this case, the parameter newValue would be undefined.
If operation is 'edit', then it returns a new object literal with the same properties and their values as obj has, except that if obj has
property prop, then this property value must be updated to the newValue parameter.

Your implementation of the function will be tested by a provided code stub on several input files. Each input file contains parameters for the function call.
The function will be called with those parameters, and the result of its execution will be printed to the standard output by the provided code. The provided
code prints the properties of the returned object ordered by their names.

Input Format For Custom Testing

The first line contains an integer, n, denoting the number of properties obj has.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains two space-separated values. The first of them is a string denoting the property of obj, and
the second one is the value of that property.
The last line contains string values for modification for obj in the format {operation} {prop} {newValue}.

Sample Case 0

Sample Input For Custom Testing

3
name John
lastName Bliss
city Florida
edit city Seattle

Sample Output

city Seattle
lastName Bliss
name John

Explanation

3/10
In this test, obj has 3 properties: name, lastName, and city. The property to edit is city, so the returned object literal contains the value 'Seattle' for the
property city, while the other two properties are the same as in obj.

Sample Case 1

Sample Input For Custom Testing

3
name John
lastName Bliss
city Florida
delete city

Sample Output

lastName Bliss
name John

Explanation
In this test, obj has 3 properties: name, lastName, and city. The property to delete is city, so the returned object literal contains properties name and
lastName but does not contains city as that has been deleted.

Sample Case 2

Sample Input For Custom Testing

3
name John
lastName Bliss
city Florida
edit abc Tor

Sample Output

city Florida
lastName Bliss
name John

Explanation
In this test, obj has 3 properties: name, lastName, and city. The property to edit is 'abc', which does not exist, so the returned object literal is the same as
the input.

Question - 4
React: User Management

There is a partially completed React application with the HTML template built and ready, and certain core React functionalities are implemented. Complete
the React application as shown in order to pass all the unit tests.

4/10
The application has 2 components:

1. The UserList.js which has the user list table which includes edit/delete buttons as actions against the row.
2. The AddEditUser.js which renders the form to enter the user details to be added or edited.

The app should implement the following functionalities:

1. AddEditUser.js
The initial view must not display any alert.
Clicking the Cancel button should:
do nothing if the fields are empty.
clear all the fields and reset them to empty.
clear the validation alert (if any).
after clicking the Edit button, discard the changes in the form and add the original user values back to the table.
Clicking the Add/Edit button should:
add field values as a row to the table with no validation alert and reset the form fields to empty.
after clicking the Edit button, add the user's updated data to the table or show a validation alert in case of any errors.

2. UserList.js
The initial view must display an empty list with no rows.
Clicking the Delete button should delete the corresponding row from the table.
Clicking the Edit button should populate the form fields where updates can be made.

3. Validations for Add/Edit User view:


Do not add a user to the list on clicking Add/Edit User and show a common 'Validation alert' if:
any of the input fields are empty.
the 'phone number' field doesn't contain 10 digits or it starts with '0'.

The following data-testid attributes are required in the component for the tests to pass:

Component Attribute

First name input firstNameInput

Last name input lastNameInput

Phone input phoneInput

Table of Users userListTable

Cancel Button cancelEditUserButton

Add/Edit Button addEditButton

Validation Alert validationAlert

Please note that the component has data-testid attributes for test cases and certain classes and ids for rendering purposes. They should not be changed.

Question - 5
React: Date API

In the given single page React project, a button click prompts an HTTP GET request to an API endpoint that returns a date as its API response. Complete the
project so it displays the current day, month, and year after clicking the button. Model the implementation after the instructions below.
Certain core React functionalities have already been implemented. Complete the React application in order to pass all the unit tests.

Demo
Link to an animated GIF

5/10
Scroll sideways below to explore the screenshots. Clicking each screenshot opens it in a new window.

Application's initial state before clicking the button.

Display date after clicking the button.

Specifications
Component flow diagram of the application is as follows:

Framework Specific Instructions


The project uses React 16 by default. Changing the React version may interfere with tests and is strictly discouraged. You may refer to the React 16 docs
here.
The project uses create-react-app and react-scripts to automate serving and testing of the application.
The project uses enzyme as a testing framework. Please refrain from changing the test framework or the tests themselves.

6/10
The project uses React Material UI as a design framework. API docs are available here and can be used as a reference.

Question - 6
NodeJS: TypeORM Stock Trades API

In this challenge, your task is to implement a simple REST API to manage a collection of stock trades.

Each trade is a JSON entry with the following keys:


id : The unique trade ID. (Integer)
type : The trade type, either 'buy' or 'sell'. (String)
user_id : The unique user ID. (Integer):
symbol : The stock symbol. (String)
shares : The total number of shares traded. The traded shares value is between 10 and 30 shares, inclusive. (Integer)
price : The price of one share of stock at the time of the trade. (Integer)
timestamp : The epoch time of the stock trade in milliseconds. (Integer)

Here is an example of a trade JSON object:

{
"id":1,
"type": "buy",
"user_id": 23,
"symbol": "ABX",
"shares": 30,
"price": 134,
"timestamp": 1531522701000
}

You are provided with the implementation of the Trade model in a project using TypeScript and TypeORM. The task is to implement the REST service that
exposes the /trades endpoint, which allows for managing the collection of trade records in the following way:

POST request to /trades :


creates a new trade
expects a JSON trade object without an id property as a body payload. You can assume that the given object is always valid.
adds the given trade object to the collection of trades and assigns a unique integer id to it. The first created trade must have id 1, the second one 2, and
so on.
the response code is 201, and the response body is the created trade object

GET request to /trades :


return a collection of all trades
the response code is 200, and the response body is an array of all trade objects ordered by their ids in increasing order

GET request to /trades/<id> :


returns a trade with the given id
if the matching trade exists, the response code is 200 and the response body is the matching trade object
if there is no trade with the given id in the collection, the response code is 404 with the response body having the text `ID not found`

DELETE , PUT , PATCH request to /trades/<id> :


the response code is 405 because the API does not allow deleting or modifying trades for any id value

You should complete the given project so that it passes all the test cases when running the provided unit tests. The project by default supports the use of
the SQLite3 database with the TypeScript based TypeORM module.

7/10
Each route added to the routes.ts file should be of type `ApplicationRequest` which is defined below:

interface ApplicationRequest {
path: string; // The URL of the request
action: (req: Request, res: Response, next?: NextFunction) => any // The middleware function to call
method: RequestMethod // The HTTP Method of the request. This is of ENUM type.
}

The definition of the enum RequestMethod is as follows:

enum RequestMethod {
GET = 'get',
POST = 'post',
PUT = 'put',
PATCH = 'patch',
DELETE = 'delete',
}

Example requests and responses

POST request to /trades


Request body:

{
"type": "buy",
"user_id": 1,
"symbol": "AC",
"shares": 28,
"price": 162,
"timestamp" : 1591514264000
}

The response code is 201, and when converted to JSON, the response body is:

{
"id": 1,
"type": "buy",
"user_id": 1,
"symbol": "AC",
"shares": 28,
"price": 162,
"timestamp" : 1591514264000
}

This adds a new object to the collection with the given properties and id 1.

GET request to /trades


The response code is 200, and when converted to JSON, the response body (assuming that the below objects are all objects in the collection) is as
follows:

[
{
"id": 1,
"type": "buy",
"user_id": 1,
"symbol": "AC",
"shares": 28,
"price": 162,
"timestamp" : 1591514264000
},
{
"id": 2,
"type": "sell",
"user_id": 1,
"symbol": "AC",
"shares": 28,

8/10
"price": 162,
"timestamp" : 1591514264000
}
]

GET request to /trades/1


Assuming that the object with id 1 exists, then the response code is 200 and the response body, when converted to JSON, is as follows:

{
"id": 1,
"type": "buy",
"user_id": 1,
"symbol": "AC",
"shares": 28,
"price": 162,
"timestamp" : 1591514264000
}

If an object with id 1 doesn't exist, then the response code is 404 with the response body having the text `ID not found`

DELETE request to /trades/1


The response code is 405 and there are no particular requirements for the response body.

Question - 7
JavaScript: Inventory List

Implement a function, inventoryList, such that:


it maintains the collection of all item names existing in an inventory, where each item is uniquely identified by a name.
returns a new object, with three methods:
add(name) - The string name parameter is passed, and it is added to the collection. Items in the collection are distinct.
remove(name) - The string name parameter is passed, and this item is removed from the collection if it exists. If it does not exist, nothing happens.
getList() - This returns an array of names of items added so far. The names are returned in the order the corresponding items were added.

Your function implementation will be tested by a stubbed code on several input files. Each input file contains parameters for the function calls. The results
of their execution will be printed to standard output by the provided code. The stubbed code joins the strings returned by the getList function by a comma
and prints to the standard output. If getList returns an empty array, the stubbed code prints 'No Items'.

Constraints:
The size of the collection will not exceed 10 at any point.
All names passed to add(name) and remove(name) are non-empty.

Input Format For Custom Testing

In the first line, there is an integer, n, denoting the number of operations to be performed.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains space-separated strings such that the first of them is a function name, and the remaining
ones, if any, are parameters for that function.

Sample Case 0

Sample Input For Custom Testing

5
add Shirt
add Trouser
getList
remove Shirt
getList

9/10
Sample Output

Shirt,Trouser
Trouser

Explanation
Items 'Shirt' and 'Trouser' are added by the add function. Then, getList is called, and the result is printed. Item 'Shirt' is removed by calling the remove
function. Finally, getList is called, and the result is printed.

Sample Case 1

Sample Input For Custom Testing

3
add Shirt
remove Trouser
getList

Sample Output

Shirt

Explanation
Item 'Shirt' is added by the add function. Then, remove is called with 'Trouser'. Since 'Trouser' does not exist, nothing happens. Finally, getList is called,
and the result is printed.

10/10

You might also like