Skip to content

Commit

Permalink
feat(jest): kickstart unit test for store/textile/actions (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed Feb 28, 2022
1 parent b8351fa commit b8d2cfb
Showing 1 changed file with 76 additions and 4 deletions.
80 changes: 76 additions & 4 deletions store/textile/actions.test.ts
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()
})
})
})

0 comments on commit b8d2cfb

Please sign in to comment.