Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated OrderHistoryFactory #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion app-new/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OrderHistoryService } from './services/OrderHistoryFactory';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

Expand All @@ -8,7 +9,7 @@ import { UpgradeModule } from '@angular/upgrade/static';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AppRoutingModule, UpgradeModule],
providers: [],
providers: [OrderHistoryService, ],
bootstrap: [AppComponent],
})
export class AppModule {}
14 changes: 14 additions & 0 deletions app-new/src/app/services/OrderHistoryFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class OrderHistoryService {
constructor(private http: HttpClient) {}

viewOrders(id: string): Observable<any> {
return this.http.get(`/api/order/${id}`);
}
}
31 changes: 31 additions & 0 deletions app-new/src/app/tests/OrderHistoryFactory.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe("OrderHistoryFactory", function () {
beforeEach(module("FullstackGeneratedApp"));
beforeEach(module("$$UpgradeModule"));

var $controller, $rootScope, $scope, $httpBackend, OrderHistoryFactory;

beforeEach(inject(function (_$controller_, _$rootScope_, _$httpBackend_, _OrderHistoryFactory_) {
$controller = _$controller_;
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
OrderHistoryFactory = _OrderHistoryFactory_;
}));

describe("viewOrders", function () {
it("should fetch order history for a given id", function () {
var testId = 123;
var mockResponse = { data: "mock order data" };
$httpBackend.expectGET("/api/order/" + testId).respond(mockResponse);

var orderHistory;
OrderHistoryFactory.viewOrders(testId).then(function (data) {
orderHistory = data;
});

$httpBackend.flush();

expect(orderHistory).toEqual(mockResponse.data);
});
});
});
12 changes: 0 additions & 12 deletions browser/js/orders/order-history.factory.js

This file was deleted.