-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: adds unit tests for syncCloudData
- Loading branch information
1 parent
85b1ce4
commit cfafce7
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
apps/meteor/tests/unit/app/cloud/server/functions/syncWorkspace/syncCloudData.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it, beforeEach } from 'mocha'; | ||
import proxyquire from 'proxyquire'; | ||
import sinon from 'sinon'; | ||
|
||
const models = { | ||
Settings: { updateValueById: sinon.stub() }, | ||
}; | ||
|
||
const mockedFetchWorkspaceSyncPayload = sinon.stub(); | ||
|
||
const { syncCloudData } = proxyquire.noCallThru().load('../../../../../../../app/cloud/server/functions/syncWorkspace/syncCloudData.ts', { | ||
'@rocket.chat/license': { DuplicatedLicenseError: sinon.stub() }, | ||
'@rocket.chat/models': models, | ||
'../../../../../lib/callbacks': { callbacks: { run: sinon.stub() } }, | ||
'../../../../../lib/errors/CloudWorkspaceAccessError': { CloudWorkspaceAccessError: sinon.stub() }, | ||
'../../../../../lib/errors/CloudWorkspaceRegistrationError': { CloudWorkspaceRegistrationError: sinon.stub() }, | ||
'../../../../../server/lib/logger/system': { SystemLogger: { info: sinon.stub(), error: sinon.stub() } }, | ||
'../buildRegistrationData': { buildWorkspaceRegistrationData: sinon.stub().resolves({}) }, | ||
'../getWorkspaceAccessToken': { | ||
getWorkspaceAccessToken: sinon.stub().resolves('token'), | ||
CloudWorkspaceAccessTokenEmptyError: sinon.stub(), | ||
}, | ||
'../retrieveRegistrationStatus': { retrieveRegistrationStatus: sinon.stub().resolves({ workspaceRegistered: true }) }, | ||
'./fetchWorkspaceSyncPayload': { fetchWorkspaceSyncPayload: mockedFetchWorkspaceSyncPayload }, | ||
}); | ||
|
||
describe('SyncCloudData', () => { | ||
beforeEach(() => { | ||
models.Settings.updateValueById.reset(); | ||
mockedFetchWorkspaceSyncPayload.reset(); | ||
}); | ||
|
||
it('should save cloudSyncAnnouncement payload on Cloud_Sync_Announcement_Payload setting when present', async () => { | ||
const workspaceSyncPayloadResponse = { | ||
workspaceId: 'workspaceId', | ||
publicKey: 'publicKey', | ||
license: {}, | ||
removeLicense: false, | ||
cloudSyncAnnouncement: { | ||
viewId: 'subscription-announcement', | ||
appId: 'cloud-announcements-core', | ||
blocks: [ | ||
{ | ||
type: 'callout', | ||
title: { | ||
type: 'plain_text', | ||
text: 'Workspace eligible for Starter Plan', | ||
}, | ||
text: { | ||
type: 'plain_text', | ||
text: 'Get free access to premium capabilities for up to 50 users', | ||
}, | ||
accessory: { | ||
type: 'button', | ||
text: { | ||
type: 'plain_text', | ||
text: 'Switch Plan', | ||
}, | ||
actionId: 'callout-action', | ||
appId: 'cloud-announcements-core', | ||
blockId: 'section-button', | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
mockedFetchWorkspaceSyncPayload.resolves(workspaceSyncPayloadResponse); | ||
|
||
await syncCloudData(); | ||
|
||
expect(mockedFetchWorkspaceSyncPayload.calledOnce).to.be.true; | ||
|
||
expect( | ||
models.Settings.updateValueById.calledOnceWith( | ||
'Cloud_Sync_Announcement_Payload', | ||
JSON.stringify(workspaceSyncPayloadResponse.cloudSyncAnnouncement), | ||
), | ||
).to.be.true; | ||
}); | ||
|
||
it("Should save as 'null' the setting update if cloudSyncAnnouncement is not present", async () => { | ||
const workspaceSyncPayloadResponse = { | ||
workspaceId: 'workspaceId', | ||
publicKey: 'publicKey', | ||
license: {}, | ||
removeLicense: false, | ||
}; | ||
|
||
mockedFetchWorkspaceSyncPayload.resolves(workspaceSyncPayloadResponse); | ||
|
||
await syncCloudData(); | ||
|
||
expect(mockedFetchWorkspaceSyncPayload.calledOnce).to.be.true; | ||
|
||
expect(models.Settings.updateValueById.calledOnce).to.be.true; | ||
|
||
expect(models.Settings.updateValueById.calledWith('Cloud_Sync_Announcement_Payload', 'null')).to.be.true; | ||
}); | ||
}); |