-
Notifications
You must be signed in to change notification settings - Fork 2
Mocked databases
cedric lombardot edited this page Oct 8, 2015
·
1 revision
Create your databases in test/e2e/support/databases/*.js
'use strict';
var config = require(process.cwd() + '/node_modules/angular-protractor-cucumber/src/support/config');
var fs = require('fs');
module.exports = function MyDatabases() {
var getJson = function (file) {
return JSON.parse(
fs.readFileSync(
file,
'utf8'
)
);
};
var mockJson = function (backend, method, url, file) {
if (method === "GET") {
backend.whenGET(url).respond(getJson(file));
} else if (method === "POST") {
backend.whenPOST(url).respond(getJson(file));
} else if (method === "DELETE") {
backend.whenDELETE(url).respond(getJson(file));
} else if (method === "PUT") {
backend.whenPUT(url).respond(getJson(file));
} else if (method === "PATCH") {
backend.whenPATCH(url).respond(getJson(file));
}
};
var initUserService = function (backend, urlApi) {
// getUsers
mockJson(backend, "GET", urlApi + '/exercices', 'src/mocks/tests/users.json');
// putUser
mockJson(backend, "PUT", urlApi + '/exercices', 'src/mocks/tests/users_PUT.json');
};
var HttpBackend = require('httpbackend');
var backend = null;
return {
/**
* Get mocked databases for ITRS
*
* File loaded by :
* I use "ITRS" mocked database
*/
initialize: function () {
var urlApi = "";
backend = new HttpBackend(browser);
if (config.isDev()) {
urlApi = JSON.parse(
fs.readFileSync(
'src/config/development.json',
'utf8'
)
).config.urlApi;
} else if (config.isStage()) {
urlApi = JSON.parse(
fs.readFileSync(
'src/config/integration.json',
'utf8'
)
).config.urlApi;
}
initUserService(backend, urlApi);
backend.whenGET('./mocks/translate/lang.json').passThrough();
backend.whenGET(/^templates\//).passThrough();
},
clear: function () {
backend.clear();
}
};
}();