Coder Social home page Coder Social logo

discount-api's Introduction

Engineering Test

The challenge

We have a system that delivers advertising materials to broadcasters.

Advertising Material is uniquely identified by a 'Clock' number e.g.

  • WNP/SWCL001/010
  • ZDW/EOWW005/010

Our sales team have some new promotions they want to offer so we need to introduce a mechanism for applying Discounts to orders.

Promotions like this can and will change over time so we need the solution to be flexible.

Broadcasters

These are the Broadcasters we deliver to

  • Viacom
  • Disney
  • Discovery
  • ITV
  • Channel 4
  • Bike Channel
  • Horse and Country

Delivery Products

  • Standard Delivery: $10
  • Express Delivery: $20

Discounts

  • Send 2 or more materials via express delivery and the price for express delivery drops to $15
  • Spend over $30 to get 10% off

What we want from you

Provide a means of defining and applying various discounts to the cost of delivering material to broadcasters.

We don't need any UI for this, we just need you to show us how it would work through its API.

Examples

Based on the both Discounts applied, the following examples should be valid:

  • send WNP/SWCL001/010 to Disney, Discovery, Viacom via Standard Delivery and Horse and Country via Express Delivery based on the defined Discounts the total should be $45.00

  • send ZDW/EOWW005/010 to Disney, Discovery, Viacom via Express Delivery based on the defined Discounts the total should be $40.50

My approach

Two implementations to add, total discount and multi buy for express delivery. I decided to do the total discount first.

I did not want to change to much of the code, so just changed the method implementation instead and kept the api methods the same. As the implementation for the discounts were increase the amount of methods in the code, I felt it would be best to extract a discount class and inject it into the order class, this way sticking to the single responsibilty principle.

The class for discounts, allows the user to decide the values for the discounts (ie percentage etc) thus not hard coding these numbers, this is sticking to the open-closed principle.

All the code was test driven. I decided to use feature testing (with capybara), to test all the parts of the objects were integrated and the examples given above were working. I felt this was better than running the script run.rb as a manual check for integration.

Although the order class has no mocks of injected classes, I felt it would be best to do this for the class I created (discount).

discount-api's People

Contributors

hanfak avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.