import {getTestBed, TestBed} from '@angular/core/testing'; import {BaseRequestOptions, HttpModule, Http,} from '@angular/http'; import {MockBackend} from '@angular/http/testing'; import {BibleService} from './bible-service'; import {Reference} from '../libs/Reference'; describe('Bible Service', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpModule], providers: [ BibleService, { provide: Http, useFactory: function (backend, defaultOptions) { return new Http(backend, defaultOptions); }, deps: [MockBackend, BaseRequestOptions] }, MockBackend, BaseRequestOptions ] }); }); it('Should get the verse: Gen 1:1', () => { let svc: BibleService = getTestBed().get(BibleService); let ref = new Reference("Gen 1:1").Section; var r = svc.getResult(ref); expect(r.msg).toBe(':)'); expect(r.ref).toBe('Genesis 1:1'); expect(r.status).toBe(0); expect(r.testament).toBe("old"); expect(r.cs.length).toBe(1); expect(r.cs[0].vss.length).toBe(1); expect(r.cs[0].vss[0].w.length).toBe(9); expect(r.cs[0].vss[0].w[0].t).toBe("In the"); }); it('Should get the passage: Gen 1:1-9', () => { let svc: BibleService = getTestBed().get(BibleService); let ref = new Reference("Gen 1:1-9").Section; var r = svc.getResult(ref); expect(r.msg).toBe(':)'); expect(r.ref).toBe('Genesis 1:1 - 9'); expect(r.status).toBe(0); expect(r.testament).toBe("old"); expect(r.cs.length).toBe(1); expect(r.cs[0].vss.length).toBe(9); expect(r.cs[0].vss[0].w.length).toBe(9); expect(r.cs[0].vss[0].w[0].t).toBe("In the"); }); it('Should return an error status', () => { let svc: BibleService = getTestBed().get(BibleService); let ref = new Reference("Gen 100:1").Section; var r = svc.getResult(ref); expect(r.msg).toBe('The requested chapter for Genesis is out of range. Please pick a chapter between 1 and 50.'); expect(r.ref).toBe("Genesis 100:1"); expect(r.status).toBe(-1); expect(r.testament).toBe(''); }); for (let j = 1; j < 67; j++) { let name = Reference.bookName(j); let book = Reference.parseBook(name); for (let i = 1; i <= book.lastchapter; i++) { it('Get Data for: ' + name + " " + i, () => { let svc: BibleService = getTestBed().get(BibleService); let ref = new Reference(name + " " + i).Section; var r = svc.getResult(ref); expect(r.msg).toBe(':)'); expect(r.ref).toBe(book.bookname + " " + i + ":1 - *"); expect(r.status).toBe(0); expect(r.cs[0].vss.length).toBeGreaterThan(1); }); } } });