Book Image

Building an E-Commerce Application with MEAN

By : Adrian Mejia
Book Image

Building an E-Commerce Application with MEAN

By: Adrian Mejia

Overview of this book

<p>MEAN stands for MongoDB, Express, AngularJS, and Node.js. It is a combination of a NoSQL database, MongoDB, with a couple of JavaScript web application frameworks, namely Express.js and Angular.js. These run on Node.js.</p> <p>There is always an ever-growing list of requirements while designing an e-commerce application, which needs to be flexible enough for easy adaptation. The MEAN stack allows you to meet those requirements on time and build responsive applications using JavaScript.</p> <p>This book will show you how to create your own e-commerce application using the MEAN stack. It will take you step by step through the parallel process of learning and building. It will also teach you to develop a production-ready, high-quality e-commerce site from scratch and will provide the knowledge you need to extend your own features to the e-commerce site.</p> <p>This book starts with a short introduction to the MEAN stack, followed by a step-by-step guide on how to build a store with AngularJS, set up a database with MongoDB, create a REST API, and wire AngularJS. It also shows you how to manage user authentication and authorization, check multiple payment platforms, add products’ search and navigation, deploy a production-ready e-commerce site, and finally add your own high-quality feature to the site.</p> <p>By the end of the book, you will be able to build and use your own e-commerce app in the real world and will also be able to add your own new features to it.</p>
Table of Contents (17 chapters)
Building an E-Commerce Application with MEAN
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Testing the new feature


Running the tests is a great way to minimize the number of bugs introduced in the application along with the new feature. Let's go ahead and test the implementation of the administrator page.

AngularJS testing

Like all other tests, we are testing our Angular controllers with the Mocha and Karma runners. Since we modified admin.controller.js, we need to test that all is working as intended. Add this new file:

/* client/app/admin/admin.controller.spec.js */

describe('AdminCtrl', function() {
  beforeEach(module('meanshopApp'));

  var Product, User, $state, $controller, controller, $scope;

  var productAttributes = [
    {_id: 1, title: 'Product1', price: 100.10, stock: 10},
    {_id: 2, title: 'Product2', price: 200.00, stock: 20}
  ];

  var userAttributes = [
    {_id: 1, name: 'User1', email: '[email protected]', provider: 'local'},
    {_id: 2, name: 'User2', email: '[email protected]', provider: 'facebook'}
  ];

  beforeEach(inject(function (_$controller_, $rootScope...