Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladay committed May 8, 2020
1 parent 038ffe1 commit 8fb1e26
Show file tree
Hide file tree
Showing 10 changed files with 533 additions and 105 deletions.
20 changes: 16 additions & 4 deletions tests/mock/model/mockFeatureRequest.js
@@ -1,22 +1,34 @@
var dataFeatureRequest1 = {
id: 1,
title: "Internal Request 1",
description: "description 1",
projectId: 1,
productId: 1,
rpmId: 1,
scopeId: "scope 1"
};

var dataFeatureRequest2 = {
id: 2,
title: "Internal Request 2",
description: "description 2",
projectId: 1,
productId: 1,
rpmId: 1,
scopeId: "scope 2"
};

var dataFeatureRequest3 = {
id: 3,
title: "Internal Request 3",
description: "description 3",
projectId: 2,
productId: 2,
rpmId: 2,
scopeId: "scope 3"
};

// There is no actual FeatureRequest model and only exists as data objects.
var mockFeatureRequest = function ($q) {
var model = mockModel("FeatureRequest", $q, dataFeatureRequest1);

return model;
};

angular.module("mock.featureRequest", []).service("FeatureRequest", mockFeatureRequest);
27 changes: 27 additions & 0 deletions tests/mock/service/mockProductsService.js
@@ -0,0 +1,27 @@
var mockProductsService = function ($q, ProductRepo, WsApi) {
var service = mockService($q);

var products = {};

service.getById = function (id) {
// @todo
return {};
}

service.getProductRemoteProducts = function (id) {
// @todo
return {};
};

service.getProducts = function () {
return products;
};

service.refreshProducts = function () {
// @todo
};

return service;
};

angular.module("mock.productsService", []).service("ProductsService", mockProductsService);
36 changes: 36 additions & 0 deletions tests/mock/service/mockRemoteProductsByProductIdService.js
@@ -0,0 +1,36 @@
var mockRemoteProductsByProductIdService = function ($q, WsApi) {
var service = mockService($q);

var productId;
var remoteProducts = {};

service.refreshRemoteProductsByProductId = function (id) {
if (productId == id) {
return;
}

if (remoteProducts) {
for (var key in remoteProducts) {
remoteProducts[key] = undefined;
}
}

if (!id) {
return;
}

productId = id;
};

service.productId = function () {
return productId;
};

service.remoteProducts = function () {
return remoteProducts;
};

return service;
};

angular.module("mock.remoteProductsByProductIdService", []).service("RemoteProductsByProductIdService", mockRemoteProductsByProductIdService);
4 changes: 4 additions & 0 deletions tests/mock/service/mockRemoteProductsService.js
Expand Up @@ -476,6 +476,10 @@ angular.module("mock.remoteProductsService", []).service("RemoteProductsService"
});
};

service.refreshRemoteProducts = function () {
return messagePromise();
};

service.ready = $q.defer().promise;

return service;
Expand Down
32 changes: 25 additions & 7 deletions tests/mock/service/mockWsApi.js
Expand Up @@ -25,7 +25,7 @@ angular.module("mock.wsApi", []).service("WsApi", function ($q) {
}
};

service.fetch = function (apiReq, parameters) {
service.fetch = function (apiReq, options) {
var payload = {};

if (fetchResponse) {
Expand Down Expand Up @@ -63,13 +63,31 @@ angular.module("mock.wsApi", []).service("WsApi", function ($q) {
}

if (apiReq.controller === mapping.FeatureRequest.push.controller) {
if (apiReq.method === 'push/1') {
payload = {
"InternalRequest": dataInternalRequest1
};
} else if (apiReq.method === 'push/0') {
return rejectPromise($q.defer());
if (apiReq.method === 'push/:requestId/:productId/:rpmId') {
var requestId = Number(options.pathValues.requestId);
var productId = Number(options.pathValues.productId);
var rpmId = Number(options.pathValues.rpmId);
var scopeId = typeof options.data === "string" ? options.data : "";

if (requestId > 0 && productId > 0 && rpmId > 0 && scopeId !== "") {
for (var key in dataInternalRequestRepo1) {
if (dataInternalRequestRepo1[key].id == requestId) {
payload = {
"FeatureRequest": {
id: requestId,
projectId: productId,
rpmId: rpmId,
scopeId: options.data
}
};

return payloadPromise($q.defer(), payload);
}
}
}
}

return rejectPromise($q.defer());
}
}

Expand Down
54 changes: 35 additions & 19 deletions tests/unit/controllers/internalRequestControllerTest.js
@@ -1,8 +1,8 @@
describe("controller: InternalRequestController", function () {
var $q, $scope, $templateCache, MockedInternalRequest, InternalRequestRepo, InternalRequestsService, RemoteProductManagerRepo, WsApi, controller;
var $q, $scope, $templateCache, MockedInternalRequest, InternalRequestRepo, InternalRequestsService, ProductRepo, ProductsService, RemoteProductsByProductIdService, WsApi, controller;

var initializeVariables = function () {
inject(function (_$compile_, _$q_, _$templateCache_, _InternalRequestRepo_, _InternalRequestsService_, _RemoteProductManagerRepo_, _WsApi_) {
inject(function (_$compile_, _$q_, _$templateCache_, _InternalRequestRepo_, _InternalRequestsService_, _ProductRepo_, _ProductsService_, _RemoteProductsByProductIdService_, _RemoteProductManagerRepo_, _WsApi_) {
$compile = _$compile_;
$q = _$q_;
$templateCache = _$templateCache_;
Expand All @@ -11,14 +11,16 @@ describe("controller: InternalRequestController", function () {

InternalRequestRepo = _InternalRequestRepo_;
InternalRequestsService = _InternalRequestsService_;
RemoteProductManagerRepo = _RemoteProductManagerRepo_;
ProductRepo = _ProductRepo_;
ProductsService = _ProductsService_;
RemoteProductsByProductIdService = _RemoteProductsByProductIdService_;

WsApi = _WsApi_;
});
};

var initializeController = function (settings) {
inject(function (_$controller_, _$rootScope_, _InternalRequestsService_, _ModalService_, _RemoteProductsService_, _UserService_) {
inject(function (_$controller_, _$rootScope_, _ModalService_, _UserService_) {
$scope = _$rootScope_.$new();

sessionStorage.role = settings && settings.role ? settings.role : "ROLE_ADMIN";
Expand All @@ -27,10 +29,11 @@ describe("controller: InternalRequestController", function () {
controller = _$controller_("InternalRequestController", {
$scope: $scope,
InternalRequestRepo: InternalRequestRepo,
InternalRequestsService: _InternalRequestsService_,
InternalRequestsService: InternalRequestsService,
ModalService: _ModalService_,
RemoteProductManagerRepo: RemoteProductManagerRepo,
RemoteProductsService: _RemoteProductsService_,
ProductRepo: ProductRepo,
ProductsService: ProductsService,
RemoteProductsByProductIdService: RemoteProductsByProductIdService,
UserService: _UserService_
});

Expand All @@ -54,7 +57,7 @@ describe("controller: InternalRequestController", function () {
module("mock.internalRequestRepo");
module("mock.internalRequestsService");
module("mock.remoteProductManagerRepo");
module("mock.remoteProductsService");
module("mock.remoteProductsByProductIdService");
module("mock.user", function ($provide) {
var User = function () {
return MockedUser;
Expand Down Expand Up @@ -93,9 +96,9 @@ describe("controller: InternalRequestController", function () {
"createInternalRequest",
"deleteInternalRequest",
"editInternalRequest",
"getRemoteProductManagerRemoteProducts",
"pushFeatureRequest",
"pushInternalRequest",
"refreshProductRemoteProducts",
"resetCreateInternalRequest",
"resetInternalRequestForms",
"updateInternalRequest"
Expand Down Expand Up @@ -174,10 +177,14 @@ describe("controller: InternalRequestController", function () {
name: "Mock Internal Request " + id
});

spyOn($scope, "resetCreateInternalRequest");

$scope.internalRequestToCreate = internalRequest;
$scope.createInternalRequest();
$scope.$digest();

expect(InternalRequestRepo.findById(id)).toEqual(internalRequest);
expect($scope.resetCreateInternalRequest).toHaveBeenCalled();
});

it("deleteInternalRequest call the repo delete method and then call cancelDeleteInternalRequest when successful", function () {
Expand Down Expand Up @@ -206,19 +213,16 @@ describe("controller: InternalRequestController", function () {
expect($scope.openModal).toHaveBeenCalled();
});

it("getRemoteProductManagerRemoteProducts return the requested Remote Products", function () {
var response;
var productManagerId = dataRemoteProductManager2.id;

response = $scope.getRemoteProductManagerRemoteProducts(productManagerId);

expect(response.id).toEqual(productManagerId);
});

it("pushFeatureRequest push a FeatureRequest", function () {
var featureRequest = dataFeatureRequest1;
var featureRequest = new mockFeatureRequest($q);

$scope.featureRequestToPush = featureRequest;
$scope.products = [
new mockProduct($q),
new mockProduct($q)
];

$scope.products[0].mock(dataProduct2);

spyOn(InternalRequestsService, "pushFeatureRequest").and.callThrough();
spyOn($scope, "cancelPushFeatureRequest");
Expand All @@ -241,10 +245,22 @@ describe("controller: InternalRequestController", function () {
expect($scope.featureRequestToPush.title).toEqual(internalRequest.title);
expect($scope.featureRequestToPush.description).toEqual(internalRequest.description);
expect($scope.featureRequestToPush.productId).toBe(null);
expect($scope.featureRequestToPush.rpmId).toBe(null);
expect($scope.featureRequestToPush.scopeId).toBe(null);
expect($scope.openModal).toHaveBeenCalled();
});

it("refreshProductRemoteProducts call refreshRemoteProductsByProductId()", function () {
var featureRequest = new mockFeatureRequest($q);
$scope.featureRequestToPush = featureRequest;

spyOn(RemoteProductsByProductIdService, "refreshRemoteProductsByProductId");

$scope.refreshProductRemoteProducts();

expect(RemoteProductsByProductIdService.refreshRemoteProductsByProductId).toHaveBeenCalled();
});

it("resetCreateInternalRequest call resetInternalRequestForms() and clear out the properties", function () {
var internalRequest = new mockInternalRequest($q);
var id = dataInternalRequestRepo1.length + 1;
Expand Down

0 comments on commit 8fb1e26

Please sign in to comment.