UNPKG

ac-node

Version:

A common module for building Atlassian Connect add-ons

120 lines (102 loc) 3.68 kB
var assert = require('assert'); var sinon = require('sinon'); var MemoryStore = require('..').MemoryStore; var Tenants = require('..').Tenants; describe('ac tenants', function () { var tenants; var store; beforeEach(function () { store = MemoryStore(); tenants = Tenants(store); }); it('should emit an installed event when a tenant is installed', function *() { var spy = sinon.spy(); var input = {id: 'test'}; tenants.on('installed', spy); yield tenants.installed(input); assert.ok(spy.called); }); it('should emit an uninstalled event when a tenant is uninstalled', function *() { var spy = sinon.spy(); var input = {id: 'test'}; tenants.on('uninstalled', spy); yield store.set(input.id, input); yield tenants.uninstalled(input.id); assert.ok(spy.called); }); it('should emit an enabled event when a tenant is enabled', function *() { var spy = sinon.spy(); var input = {id: 'test'}; tenants.on('enabled', spy); yield store.set(input.id, input); yield tenants.enabled(input); assert.ok(spy.called); }); it('should emit a disabled event when a tenant is disabled', function *() { var spy = sinon.spy(); var input = {id: 'test'}; tenants.on('disabled', spy); yield store.set(input.id, input); yield tenants.disabled(input); assert.ok(spy.called); }); it('should set a tenant to enabled when installed', function *() { var input = {id: 'test'}; var tenant = yield tenants.installed(input); assert.ok(tenant.enabled); }); it('should set a tenant to disabled when uninstalled', function *() { var input = {id: 'test', enabled: true}; yield store.set(input.id, input); var tenant = yield tenants.uninstalled('test'); assert.ok(!tenant.enabled); }); it('should set a tenant to enabled when enabled', function *() { var input = {id: 'test', enabled: false}; yield store.set(input.id, input); var tenant = yield tenants.enabled(input); assert.ok(tenant.enabled); }); it('should set a tenant to disabled when disabled', function *() { var input = {id: 'test', enabled: true}; yield store.set(input.id, input); var tenant = yield tenants.disabled(input); assert.ok(!tenant.enabled); }); it('should update the store when a tenant is installed', function *() { var input = {id: 'test'}; tenants.installed(input); var tenant = yield store.get(input.id); assert.ok(tenant); assert.equal('test', tenant.id); }); it('should update the store when a tenant is uninstalled', function *() { var input = {id: 'test'}; yield tenants.uninstalled(input.id); var tenant = yield store.get(input.id); assert.ok(!tenant); }); it('should update the store when a tenant is enabled', function *() { var input = {id: 'test', enabled: false}; yield store.set(input.id, input); yield tenants.enabled(input); var tenant = yield store.get(input.id); assert.ok(tenant.enabled); }); it('should update the store when a tenant is disabled', function *() { var input = {id: 'test', enabled: true}; yield store.set(input.id, input); yield tenants.disabled(input); var tenant = yield store.get(input.id); assert.ok(!tenant.enabled); }); it('should clear all tenant data from the store when uninstalled', function *() { var input = {id: 'test', enabled: true}; yield store.set(input.id, input); var tenantStore = store.narrow(input.id); yield tenantStore.set('foo', 'bar'); yield tenants.uninstalled(input.id); var value = yield tenantStore.get('foo'); assert.ok(!value); }); });