-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest): kickstart unit test for store/textile/actions (#1750)
- Loading branch information
Showing
1 changed file
with
76 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,80 @@ | ||
import Vue from 'vue' | ||
import { TextileError } from './types' | ||
import * as actions from '~/store/textile/actions' | ||
import * as Logger from '~/utilities/Logger' | ||
import TextileManager from '~/libraries/Textile/TextileManager' | ||
import { TextileFileSystem } from '~/libraries/Files/TextileFileSystem' | ||
import { Config } from '~/config' | ||
|
||
describe.skip('actions.default.subscribeToSentbox', () => { | ||
// AP-377 | ||
test('0', async () => { | ||
await actions.default.subscribeToSentbox() | ||
Vue.prototype.$Config = Config | ||
|
||
const DefaultLogger = Logger.default | ||
Vue.prototype.$Logger = new DefaultLogger(Vue.prototype.$Config.debug) | ||
Vue.prototype.$TextileManager = new TextileManager() | ||
Vue.prototype.$FileSystem = new TextileFileSystem() | ||
|
||
describe('actions.default.initialize', () => { | ||
test('', async () => { | ||
try { | ||
const commit = jest.fn() | ||
const JestTextileManager = Vue.prototype.$TextileManager | ||
JestTextileManager.init = jest.fn() | ||
JestTextileManager.getIdentityPublicKey = jest.fn() | ||
JestTextileManager.getIdentityPublicKey.mockReturnValueOnce('public key') | ||
JestTextileManager.bucket = jest.fn() | ||
JestTextileManager.bucket.index = jest.fn() | ||
JestTextileManager.bucket.index.mockReturnValueOnce('index') | ||
const JestFS = Vue.prototype.$FileSystem | ||
JestFS.import = jest.fn() | ||
await actions.default.initialize({ commit }, { id: 'id', pass: 'pass' }) | ||
expect(JestTextileManager.init).toHaveBeenCalled() | ||
expect(JestTextileManager.init).toHaveBeenCalledWith({ | ||
id: 'id', | ||
pass: 'pass', | ||
}) | ||
expect(JestTextileManager.getIdentityPublicKey).toHaveBeenCalled() | ||
expect(commit).toHaveBeenCalledWith('textileInitialized', true) | ||
expect(commit).toHaveBeenCalledWith( | ||
'accounts/updateTextilePubkey', | ||
'public key', | ||
{ root: true }, | ||
) | ||
expect(JestFS.import).toHaveBeenCalled() | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
}) | ||
}) | ||
|
||
describe('actions.default.clearUploadStatus', () => { | ||
test('', () => { | ||
const commit = jest.fn() | ||
actions.default.clearUploadStatus({ commit }) | ||
expect(commit).toHaveBeenCalledWith('clearUploadProgress', {}) | ||
}) | ||
}) | ||
|
||
describe('actions.default.subscribeToSentbox', () => { | ||
test('Mailbox Manager does not exist', async () => { | ||
try { | ||
await actions.default.subscribeToSentbox() | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(Error) | ||
expect(error).toHaveProperty( | ||
'message', | ||
TextileError.MAILBOX_MANAGER_NOT_FOUND, | ||
) | ||
} | ||
}) | ||
test.skip('Mailbox Manager exists', async () => { | ||
// On progress | ||
const JestTextileManager = Vue.prototype.$TextileManager | ||
|
||
const JestMailboxManager = JestTextileManager.mailboxManager | ||
await JestTextileManager.authenticate('id', 'pass', {}).then(async () => { | ||
JestMailboxManager.isSubscribed = jest.fn() | ||
JestMailboxManager.isSubscribed.mockReturnValueOnce(true) | ||
await actions.default.subscribeToSentbox() | ||
}) | ||
}) | ||
}) |