@webda/core
Version:
Expose API with Lambda
78 lines • 3.46 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { suite, test } from "@testdeck/mocha";
import * as assert from "assert";
import { Service } from "...js";
import { WebdaTest } from "../test.js";
import { MultiNotificationService } from "./notificationservice.js";
class FakeNotification extends Service {
constructor() {
super(...arguments);
this.template = false;
this.user = false;
this.sent = 0;
}
async hasNotification(notification) {
return this.template;
}
async handleNotificationFor(user) {
return this.user;
}
async sendNotification(user, notification, replacements) {
this.sent++;
}
}
let NotificationServiceTest = class NotificationServiceTest extends WebdaTest {
getTestConfiguration() {
return process.cwd() + "/test/config-invitation.json";
}
async before() {
await super.before();
this.service = new MultiNotificationService(this.webda, "notif", {
senders: ["notifA", "notifB"]
});
this.fakeA = new FakeNotification(this.webda, "notifA", {});
this.fakeB = new FakeNotification(this.webda, "notifB", {});
this.registerService(this.fakeA);
this.registerService(this.fakeB);
this.registerService(this.service);
this.service.resolve();
}
async cov() {
assert.strictEqual(await this.service.handleNotificationFor(undefined), false);
assert.strictEqual(await this.service.hasNotification(undefined), false);
this.fakeB.user = true;
assert.strictEqual(await this.service.handleNotificationFor(undefined), true);
this.fakeA.template = true;
assert.strictEqual(await this.service.hasNotification(undefined), true);
await this.service.sendNotification(undefined, undefined, undefined);
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 0);
this.fakeA.user = true;
await this.service.sendNotification(undefined, undefined, undefined);
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 1);
this.fakeB.template = true;
await this.service.sendNotification(undefined, undefined, undefined);
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 2);
this.service.getParameters().multiple = true;
await this.service.sendNotification(undefined, undefined, undefined);
assert.strictEqual(this.fakeA.sent + this.fakeB.sent, 4);
}
async exception() {
this.service.getParameters().senders.push("unknown");
assert.throws(() => this.service.resolve(), /Unknown service 'unknown'/);
}
};
__decorate([
test
], NotificationServiceTest.prototype, "cov", null);
__decorate([
test
], NotificationServiceTest.prototype, "exception", null);
NotificationServiceTest = __decorate([
suite
], NotificationServiceTest);
//# sourceMappingURL=notificationservice.spec.js.map