Browse Source

Tests fixed

pull/1/head
Sebastian 9 years ago
parent
commit
42bd301103
  1. 15
      src/Squidex/app/framework/utils/immutable-array.spec.ts
  2. 4
      src/Squidex/app/shared/services/contents.service.spec.ts
  3. 106
      src/Squidex/app/shared/services/event-consumers.service.spec.ts
  4. 3
      src/Squidex/app/shared/services/event-consumers.service.ts
  5. 73
      src/Squidex/app/shared/services/help.service.spec.ts
  6. 2
      src/Squidex/app/shared/services/help.service.ts

15
src/Squidex/app/framework/utils/immutable-array.spec.ts

@ -47,6 +47,21 @@ describe('ImmutableArray', () => {
expect(array_2).toBe(array_1); expect(array_2).toBe(array_1);
}); });
it('should push front items', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.pushFront(4, 5);
expect(array_2.length).toBe(5);
expect(array_2.values).toEqual([4, 5, 1, 2, 3]);
});
it('should return same array if pushing zero items to the front', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.pushFront();
expect(array_2).toBe(array_1);
});
it('should remove item', () => { it('should remove item', () => {
const array_1 = ImmutableArray.of([1, 2, 3]); const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.remove(2); const array_2 = array_1.remove(2);

4
src/Squidex/app/shared/services/contents.service.spec.ts

@ -73,7 +73,7 @@ describe('ContentsService', () => {
authService.verifyAll(); authService.verifyAll();
}); });
it('should make append query to get request as search', () => { it('should append query to get request as search', () => {
authService.setup(x => x.authGet('http://service/p/api/content/my-app/my-schema?nonPublished=true&hidden=true&$search=my-query&$top=17&$skip=13')) authService.setup(x => x.authGet('http://service/p/api/content/my-app/my-schema?nonPublished=true&hidden=true&$search=my-query&$top=17&$skip=13'))
.returns(() => Observable.of( .returns(() => Observable.of(
new Response( new Response(
@ -95,7 +95,7 @@ describe('ContentsService', () => {
authService.verifyAll(); authService.verifyAll();
}); });
it('should make append query to get request as plain', () => { it('should append query to get request as plain query string', () => {
authService.setup(x => x.authGet('http://service/p/api/content/my-app/my-schema?nonPublished=true&hidden=true&$filter=my-filter&$top=17&$skip=13')) authService.setup(x => x.authGet('http://service/p/api/content/my-app/my-schema?nonPublished=true&hidden=true&$filter=my-filter&$top=17&$skip=13'))
.returns(() => Observable.of( .returns(() => Observable.of(
new Response( new Response(

106
src/Squidex/app/shared/services/event-consumers.service.spec.ts

@ -0,0 +1,106 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { Response, ResponseOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
ApiUrlConfig,
AuthService,
EventConsumerDto,
EventConsumersService
} from './../';
describe('EventConsumersService', () => {
let authService: IMock<AuthService>;
let eventConsumersService: EventConsumersService;
beforeEach(() => {
authService = Mock.ofType(AuthService);
eventConsumersService = new EventConsumersService(authService.object, new ApiUrlConfig('http://service/p/'));
});
it('should make get request to get event consumers', () => {
authService.setup(x => x.authGet('http://service/p/api/event-consumers'))
.returns(() => Observable.of(
new Response(
new ResponseOptions({
body: [{
name: 'event-consumer1',
lastHandledEventNumber: 13,
isStopped: true,
isResetting: true,
error: 'an error 1'
}, {
name: 'event-consumer2',
lastHandledEventNumber: 29,
isStopped: true,
isResetting: true,
error: 'an error 2'
}]
})
)
))
.verifiable(Times.once());
let eventConsumers: EventConsumerDto[] | null = null;
eventConsumersService.getEventConsumers().subscribe(result => {
eventConsumers = result;
}).unsubscribe();
expect(eventConsumers).toEqual([
new EventConsumerDto('event-consumer1', 13, true, true, 'an error 1'),
new EventConsumerDto('event-consumer2', 29, true, true, 'an error 2')
]);
authService.verifyAll();
});
it('should make put request to start event consumer', () => {
authService.setup(x => x.authPut('http://service/p/api/event-consumers/event-consumer1/start', It.isAny()))
.returns(() => Observable.of(
new Response(
new ResponseOptions()
)
))
.verifiable(Times.once());
eventConsumersService.startEventConsumer('event-consumer1');
authService.verifyAll();
});
it('should make put request to stop event consumer', () => {
authService.setup(x => x.authPut('http://service/p/api/event-consumers/event-consumer1/stop', It.isAny()))
.returns(() => Observable.of(
new Response(
new ResponseOptions()
)
))
.verifiable(Times.once());
eventConsumersService.stopEventConsumer('event-consumer1');
authService.verifyAll();
});
it('should make put request to reset event consumer', () => {
authService.setup(x => x.authPut('http://service/p/api/event-consumers/event-consumer1/reset', It.isAny()))
.returns(() => Observable.of(
new Response(
new ResponseOptions()
)
))
.verifiable(Times.once());
eventConsumersService.resetEventConsumer('event-consumer1');
authService.verifyAll();
});
});

3
src/Squidex/app/shared/services/event-consumers.service.ts

@ -56,7 +56,6 @@ export class EventConsumersService {
const url = this.apiUrl.buildUrl(`api/event-consumers/${name}/start`); const url = this.apiUrl.buildUrl(`api/event-consumers/${name}/start`);
return this.authService.authPut(url, {}) return this.authService.authPut(url, {})
.map(response => response.json())
.catchError('Failed to start event consumer. Please reload.'); .catchError('Failed to start event consumer. Please reload.');
} }
@ -64,7 +63,6 @@ export class EventConsumersService {
const url = this.apiUrl.buildUrl(`api/event-consumers/${name}/stop`); const url = this.apiUrl.buildUrl(`api/event-consumers/${name}/stop`);
return this.authService.authPut(url, {}) return this.authService.authPut(url, {})
.map(response => response.json())
.catchError('Failed to stop event consumer. Please reload.'); .catchError('Failed to stop event consumer. Please reload.');
} }
@ -72,7 +70,6 @@ export class EventConsumersService {
const url = this.apiUrl.buildUrl(`api/event-consumers/${name}/reset`); const url = this.apiUrl.buildUrl(`api/event-consumers/${name}/reset`);
return this.authService.authPut(url, {}) return this.authService.authPut(url, {})
.map(response => response.json())
.catchError('Failed to reset event consumer. Please reload.'); .catchError('Failed to reset event consumer. Please reload.');
} }
} }

73
src/Squidex/app/shared/services/help.service.spec.ts

@ -0,0 +1,73 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { Http, Response, ResponseOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { IMock, Mock, Times } from 'typemoq';
import { HelpService } from './../';
describe('AppClientsService', () => {
let helpService: HelpService;
let http: IMock<Http>;
beforeEach(() => {
http = Mock.ofType(Http);
helpService = new HelpService(http.object);
});
it('should make get request to get help sections', () => {
http.setup(x => x.get('https://api.gitbook.com/book/squidex/squidex/contents/01-chapter/02-article.json'))
.returns(() => Observable.of(
new Response(
new ResponseOptions({
body: {
sections: [{
content: 'A test content with'
}, {
content: 'A test content with a <a href="https://squidex.io">A Link</a>'
}, {
content: 'A test content with a <a href="../GLOSSARY.html#content">Glossary Link</a>'
}]
}
})
)
))
.verifiable(Times.once());
let helpSections: string[] | null = null;
helpService.getHelp('01-chapter/02-article').subscribe(result => {
helpSections = result;
});
expect(helpSections).toEqual([
'A test content with',
'A test content with a <a href="https://squidex.io">A Link</a>',
'A test content with a <a target="_blank" href="https://docs.squidex.io/GLOSSARY.html#content">Glossary Link</a>'
]);
http.verifyAll();
});
it('should return empty sections if get request fails', () => {
http.setup(x => x.get('https://api.gitbook.com/book/squidex/squidex/contents/01-chapter/02-article.json'))
.returns(() => Observable.throw('An error'))
.verifiable(Times.once());
let helpSections: string[] | null = null;
helpService.getHelp('01-chapter/02-article').subscribe(result => {
helpSections = result;
});
expect(helpSections).toEqual([]);
http.verifyAll();
});
});

2
src/Squidex/app/shared/services/help.service.ts

@ -32,6 +32,6 @@ export class HelpService {
return result; return result;
}) })
.catch(err => []); .catch(err => Observable.of([]));
} }
} }
Loading…
Cancel
Save