Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AccountForm.vue.spec.js « components « unit « tests « src - github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dfc0900864818f0aff9c9939f311590f92e1dddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * @copyright 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
 *
 * @author 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import { testConnectivity, queryIspdb, queryMx } from '../../../service/AutoConfigService'
import {createLocalVue, shallowMount} from '@vue/test-utils'

import AccountForm from '../../../components/AccountForm'
import Nextcloud from '../../../mixins/Nextcloud'

const localVue = createLocalVue()

localVue.mixin(Nextcloud)

jest.mock('../../../service/AutoConfigService')

describe('AccountForm', () => {

	let view
	let save

	beforeEach(() => {
		save = jest.fn()
		view = shallowMount(AccountForm, {
			propsData: {
				displayName: 'Tom Turbo',
				email: 'tom@tom.turbo',
				save,
			},
			localVue,
		})
	})

	it('uses name and email from nextcloud account', () => {
		expect(view.vm.accountName).toBe('Tom Turbo')
		expect(view.vm.emailAddress).toBe('tom@tom.turbo')
	})

	it('applies server ISP DB config', async() => {
		queryIspdb.mockImplementation(() => Promise.resolve({
			imapConfig: {
				host: 'imap.tom.turbo',
				port: 993,
				security: 'ssl',
				username: 'tom',
			},
			smtpConfig: {
				host: 'smtp.tom.turbo',
				port: 465,
				security: 'ssl',
				username: 'tom',
			},
		}))

		view.vm.autoConfig.password = 'secret'
		const detected = await view.vm.detectConfig()

		expect(queryIspdb).toHaveBeenCalled()
		expect(queryMx).not.toHaveBeenCalled()
		expect(detected).toBe(true)
		expect(view.vm.manualConfig.imapUser).toBe('tom')
		expect(view.vm.manualConfig.imapHost).toBe('imap.tom.turbo')
		expect(view.vm.manualConfig.imapPort).toBe(993)
		expect(view.vm.manualConfig.imapSslMode).toBe('ssl')
		expect(view.vm.manualConfig.imapPassword).toBe('secret')
		expect(view.vm.manualConfig.smtpUser).toBe('tom')
		expect(view.vm.manualConfig.smtpHost).toBe('smtp.tom.turbo')
		expect(view.vm.manualConfig.smtpPort).toBe(465)
		expect(view.vm.manualConfig.smtpSslMode).toBe('ssl')
		expect(view.vm.manualConfig.smtpPassword).toBe('secret')
	})

	it('fails to find auto config', async() => {
		queryIspdb.mockImplementation(() => Promise.resolve(undefined))
		queryMx.mockImplementation(() => Promise.resolve(['mx.tom.turbo']))
		testConnectivity.mockImplementation(() => Promise.resolve(false))

		view.vm.autoConfig.password = 'secret'
		const detected = await view.vm.detectConfig()

		expect(queryIspdb).toHaveBeenCalled()
		expect(queryMx).toHaveBeenCalled()
		expect(testConnectivity).toHaveBeenCalledTimes(4)
		expect(detected).toBe(false)
		expect(view.vm.error).not.toBe(null)
	})

	it('applies server MX config', async() => {
		queryIspdb.mockImplementation(() => Promise.resolve(undefined))
		queryMx.mockImplementation(() => Promise.resolve(['mx.tom.turbo']))
		testConnectivity.mockImplementation((host, port) => Promise.resolve(host === 'mx.tom.turbo' && [993, 465].includes(port)))

		view.vm.autoConfig.password = 'secret'
		const detected = await view.vm.detectConfig()

		expect(queryIspdb).toHaveBeenCalled()
		expect(queryMx).toHaveBeenCalled()
		expect(testConnectivity).toHaveBeenCalledTimes(8)
		expect(detected).toBe(true)
		expect(view.vm.manualConfig.imapUser).toBe('tom@tom.turbo')
		expect(view.vm.manualConfig.imapHost).toBe('mx.tom.turbo')
		expect(view.vm.manualConfig.imapPort).toBe(993)
		expect(view.vm.manualConfig.imapSslMode).toBe('ssl')
		expect(view.vm.manualConfig.imapPassword).toBe('secret')
		expect(view.vm.manualConfig.smtpUser).toBe('tom@tom.turbo')
		expect(view.vm.manualConfig.smtpHost).toBe('mx.tom.turbo')
		expect(view.vm.manualConfig.smtpPort).toBe(465)
		expect(view.vm.manualConfig.smtpSslMode).toBe('ssl')
		expect(view.vm.manualConfig.smtpPassword).toBe('secret')
	})

})