https://github.com/salesforcecommercecloud/dw-api-mock
Mock version of DW API
https://github.com/salesforcecommercecloud/dw-api-mock
Last synced: about 1 year ago
JSON representation
Mock version of DW API
- Host: GitHub
- URL: https://github.com/salesforcecommercecloud/dw-api-mock
- Owner: SalesforceCommerceCloud
- License: bsd-3-clause
- Created: 2018-06-26T17:54:23.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-09-16T06:40:46.000Z (almost 2 years ago)
- Last Synced: 2024-09-16T07:59:29.511Z (almost 2 years ago)
- Language: JavaScript
- Size: 527 KB
- Stars: 23
- Watchers: 13
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
DW MOCK API
===========
--------------------------
Introduction
------------
This is a mock API or an API stub for the Demandware Script API, the main goal is to make unit testing easier so that not every single Class/Object needs to be stubbed out.
Example usage
-------------
It has been tested to work well in conjunction with mochajs as a testrunner and chai, sinon, sinon-chai and proxyquire as utility libs.
A unit test would then look something like
```
#!javascript
'use strict';
// jscs:disable jsDoc
var describe = require('mocha').describe;
var it = require('mocha').it;
var chai = require("chai");
var sinon = require("sinon");
var sinonChai = require("sinon-chai");
var expect = chai.expect;
var proxyquire = require('proxyquire').noCallThru();
chai.use(sinonChai);
require.extensions['.ds'] = require.extensions['.js'];
require('dw-api-mock/demandware-globals');
// add cartridges dir as module lookup location, the app-module-path package lets you do this nicely
require('app-module-path').addPath(process.cwd() + '/cartridges');
describe("Product Model", function() {
it("should return a variation model", function() {
var ProductModel = require('app_storefront_controller/cartridge/scripts/models/ProductModel');
var instance = new ProductModel(new dw.catalog.Product());
expect(instance.getVariationModel()).to.exist.
});
});
```
All the dependencies can be added to the root of your repository into a `package.json` file and the unit tests would be inside a test folder, so you would have
* cartridges
* site_import
* test
Sample package.json
```
{
"name": "my-repo",
"version": "1.0.0",
"description": "A repo description",
"main": "index.js",
"directories": {
"test": "test"
},
"devDependencies": {
"app-module-path": "^1.0.4",
"chai": "^3.4.1",
"dw-api-mock": "git+ssh://github.com/SalesforceCommerceCloud/dw-api-mock.git",
"istanbul": "^0.4.1",
"mocha": "^2.3.4",
"proxyquire": "^1.7.3",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0",
"xunit-file": "0.0.7"
},
"scripts": {
"test": "mocha test/*",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha"
},
"keywords": [
"myrepo"
],
"author": "Your Name",
"license": "UNLICENSED",
"homepage": "www.yourhomepage.com"
}
```
Now you can simply run
```
#!bash
$ npm install
$ mocha test/*
```
License
-------
Licensed under the current NDA and licensing agreement in place with your organization. (This is explicitly not open source licensing.)