-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ajax-form-call.es6
102 lines (92 loc) · 2.92 KB
/
test.ajax-form-call.es6
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
import sinon from 'sinon';
import AjaxFormCallClass from '../src/models/AjaxFormCall';
describe('ajax-call: AjaxFormCall', () => {
it('Constructor', function(done) {
var AjaxFormCall = new AjaxFormCallClass();
AjaxFormCall.should.containEql({});
AjaxFormCall.should.have.property('result', 0);
AjaxFormCall.should.have.property('message', '');
AjaxFormCall.should.have.property('value', {});
AjaxFormCall.should.have.property('errors', {});
AjaxFormCall.should.have.property('countErrors', 0);
done();
});
it('Add error', (done) => {
var AjaxFormCall = new AjaxFormCallClass();
AjaxFormCall.addError('nameError', 'err');
AjaxFormCall.should.have.property('result', 400);
AjaxFormCall.should.have.property('message', '');
AjaxFormCall.should.have.property('value', {});
AjaxFormCall.errors.should.eql({
'nameError': ['err']
});
done();
});
it('Add more error', (done) => {
var AjaxFormCall = new AjaxFormCallClass();
AjaxFormCall.addError('nameError', 'err1');
AjaxFormCall.addError('nameError', 'err2');
AjaxFormCall.should.have.property('result', 400);
AjaxFormCall.should.have.property('message', '');
AjaxFormCall.should.have.property('value', {});
AjaxFormCall.errors.should.eql({
'nameError': ['err1', 'err2']
});
done();
});
it('Add more more error', (done) => {
var AjaxFormCall = new AjaxFormCallClass();
AjaxFormCall.addError('nameError', 'err1');
AjaxFormCall.addError('nameError', 'err2');
AjaxFormCall.addError('anotherNameError', 'err3');
AjaxFormCall.should.have.property('result', 400);
AjaxFormCall.should.have.property('message', '');
AjaxFormCall.should.have.property('value', {});
AjaxFormCall.errors.should.eql({
'nameError': ['err1', 'err2'],
'anotherNameError': ['err3']
});
done();
});
it('get struct empty', (done) => {
var AjaxFormCall = new AjaxFormCallClass();
var struct = AjaxFormCall.getStruct();
struct.should.eql({
code: 0,
success: true,
result: 0,
message: '',
value: {},
errors: {},
countErrors: 0
});
done();
});
it('get struct empty', (done) => {
var AjaxFormCall = new AjaxFormCallClass();
AjaxFormCall.addError('nameError', 'err1');
AjaxFormCall.addError('nameError', 'err2');
AjaxFormCall.addError('anotherNameError', 'err3');
var struct = AjaxFormCall.getStruct();
struct.should.eql({
code: 1,
success: false,
result: 1,
message: '',
value: {},
errors: {
'nameError': ['err1', 'err2'],
'anotherNameError': ['err3']
},
countErrors: 3
});
done();
});
it('has Error', (done) => {
var AjaxFormCall = new AjaxFormCallClass();
AjaxFormCall.hasError().should.equal(false);
AjaxFormCall.addError('nameError', 'err');
AjaxFormCall.hasError().should.equal(true);
done();
});
});