Skip to content

Commit

Permalink
feat(jest): fixed warnings, 8% coverage for store/textile/actions (#3343
Browse files Browse the repository at this point in the history
)
  • Loading branch information
drepram committed May 28, 2022
1 parent cd28660 commit 9a357e4
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions store/textile/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ describe('actions.default.initialize', () => {

// Mocks for the arguments
const commit = jest.fn()
const dispatch = 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 = fs.export

await actions.default.initialize({ commit }, { id: 'id', pass: 'pass' })
await actions.default.initialize(
{ commit, dispatch },
{ id: 'id', pass: 'pass' },
)

expect(JestTextileManager.init).toHaveBeenCalled()
expect(JestTextileManager.init).toHaveBeenCalledWith({
Expand All @@ -70,25 +74,25 @@ describe('actions.default.initialize', () => {
console.error(error)
}
})
test('initialize without record.consent_scan', async () => {
test('initialize with record', async () => {
try {
// Mocks so we have a fs.export
const mockFileData = {
name: 'TestFile1.png',
name: 'TestFile4.png',
hash: '0x0aef',
size: 42345,
descrption: 'Test file description',
}

const mockDirectoryData = {
name: 'dir1',
name: 'dir4',
liked: false,
shared: false,
type: DIRECTORY_TYPE.DEFAULT,
}

const file = new Fil(mockFileData)
const file2 = new Fil({ ...mockFileData, name: 'testPng3.png' })
const file2 = new Fil({ ...mockFileData, name: 'testPng4.png' })
const fs = new FilSystem()

fs.addChild(file)
Expand All @@ -98,6 +102,7 @@ describe('actions.default.initialize', () => {

// Mocks for the arguments
const commit = jest.fn()
const dispatch = jest.fn()
const JestTextileManager = Vue.prototype.$TextileManager
JestTextileManager.init = jest.fn()
JestTextileManager.getIdentityPublicKey = jest.fn()
Expand All @@ -107,11 +112,12 @@ describe('actions.default.initialize', () => {
JestTextileManager.userInfoManager = jest.fn()
JestTextileManager.userInfoManager.getUserRecord = jest
.fn()
.mockReturnValueOnce({
consent_scan: true,
})
.mockReturnValueOnce('record')

await actions.default.initialize({ commit }, { id: 'id', pass: 'pass' })
await actions.default.initialize(
{ commit, dispatch },
{ id: 'id', pass: 'pass' },
)

expect(JestTextileManager.init).toHaveBeenCalled()
expect(JestTextileManager.init).toHaveBeenCalledWith({
Expand All @@ -124,37 +130,31 @@ describe('actions.default.initialize', () => {
'public key',
{ root: true },
)
expect(commit).toHaveBeenCalledWith(
'textile/updateUserThreadData',
true,
{
root: true,
},
)
expect(commit).toHaveBeenCalledWith('setUserThreadData', 'record')
} catch (error) {
// eslint-disable-next-line no-console
console.error(error)
}
})
test('initialize without record.block_nsfw', async () => {
test('initialize without record', async () => {
try {
// Mocks so we have a fs.export
const mockFileData = {
name: 'TestFile2.png',
name: 'TestFile1.png',
hash: '0x0aef',
size: 42345,
descrption: 'Test file description',
}

const mockDirectoryData = {
name: 'dir2',
name: 'dir1',
liked: false,
shared: false,
type: DIRECTORY_TYPE.DEFAULT,
}

const file = new Fil(mockFileData)
const file2 = new Fil({ ...mockFileData, name: 'testPng4.png' })
const file2 = new Fil({ ...mockFileData, name: 'testPng3.png' })
const fs = new FilSystem()

fs.addChild(file)
Expand All @@ -164,6 +164,7 @@ describe('actions.default.initialize', () => {

// Mocks for the arguments
const commit = jest.fn()
const dispatch = jest.fn()
const JestTextileManager = Vue.prototype.$TextileManager
JestTextileManager.init = jest.fn()
JestTextileManager.getIdentityPublicKey = jest.fn()
Expand All @@ -173,11 +174,12 @@ describe('actions.default.initialize', () => {
JestTextileManager.userInfoManager = jest.fn()
JestTextileManager.userInfoManager.getUserRecord = jest
.fn()
.mockReturnValueOnce({
block_nsfw: true,
})
.mockReturnValueOnce(false)

await actions.default.initialize({ commit }, { id: 'id', pass: 'pass' })
await actions.default.initialize(
{ commit, dispatch },
{ id: 'id', pass: 'pass' },
)

expect(JestTextileManager.init).toHaveBeenCalled()
expect(JestTextileManager.init).toHaveBeenCalledWith({
Expand All @@ -190,13 +192,10 @@ describe('actions.default.initialize', () => {
'public key',
{ root: true },
)
expect(commit).toHaveBeenCalledWith(
'textile/updateUserThreadData',
true,
{
root: true,
},
)
expect(dispatch).toHaveBeenCalledWith('updateUserThreadData', {
consentToScan: false,
blockNsfw: true,
})
} catch (error) {
// eslint-disable-next-line no-console
console.error(error)
Expand Down

0 comments on commit 9a357e4

Please sign in to comment.