/code-test

Developer Code Test

Primary LanguageGoMIT LicenseMIT

Ravelin Code Test

Summary

We need an HTTP server that will accept any POST request (JSON) from multiple clients' websites. Each request forms part of a struct (for that particular visitor) that will be printed to the terminal when the struct is fully complete.

For the JS part of the test please feel free to use any libraries that may help you but please only use the Go standard library for the backend. Remember to keep things simple.

Frontend (JS)

Insert JavaScript into the index.html (supplied) that captures and posts data every time one of the below events happens; this means you will be posting multiple times per visitor. Assume only one resize occurs.

  • if the screen resizes, the before and after dimensions
  • copy & paste (for each field)
  • time taken from the 1st character typed to clicking the submit button

Example JSON Requests

{
  "eventType": "copyAndPaste",
  "websiteUrl": "https://ravelin.com",
  "sessionId": "123123-123123-123123123",
  "pasted": true,
  "formId": "inputCardNumber"
}

{
  "eventType": "timeTaken",
  "websiteUrl": "https://ravelin.com",
  "sessionId": "123123-123123-123123123",
  "time": 72, // seconds
}

...

Backend (Go)

Part 1

The Backend should:

  1. Create a Server
  2. Accept POST requests in JSON format similar to those specified above
  3. Map the JSON requests to relevant sections of the data struct (specified below)
  4. Print the struct for each stage of its construction
  5. Also print the struct when it is complete (i.e. when the form submit button has been clicked)

Part 2

  1. Write a simple hashing function (your implementation - either of your own design or a known algorithm), that given a string will calculate a hash of that string. We are not looking for you to wrap a standard function, but to provide the implementation itself.
  2. Use that function to calculate the hash of the WebSiteurl field and print the hash, and print out the hash once calculated.

Go Struct

type Data struct {
	WebsiteUrl         string
	SessionId          string
	ResizeFrom         Dimension
	ResizeTo           Dimension
	CopyAndPaste       map[string]bool // map[fieldId]true
	Time int // Seconds
}

type Dimension struct {
	Width  string
	Height string
}