forked from denmark-io/denmark-real-estate-valuation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
109 lines (97 loc) · 3.51 KB
/
test.js
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
'use strict';
'use strong';
const test = require('tap').test;
const endpoint = require('endpoint');
const RealEstatValuation = require('./index.js');
function isNumber(val) {
// Some of the values may be NaN
return typeof val === 'number';
}
function isString(val) {
return typeof val === 'string';
}
test('correct zipCode and street name', function (t) {
new RealEstatValuation({ zipCode: 2800, streetName: 'Lyngby Hovedgade' })
.pipe(endpoint({objectMode: true}, function (err, evaluations) {
t.ifError(err);
t.ok(evaluations.length > 0);
for (const item of evaluations) {
t.ok(isNumber(item.id), 'id is number');
t.ok(isString(item.houseNumber), 'house number is string');
t.ok(isString(item.floor), 'floor is string');
t.ok(isString(item.type), 'type is string');
t.ok(isNumber(item.landValue), 'land value is number');
t.ok(isNumber(item.houseValue), 'house value is number');
}
t.end();
}));
});
test('correct municipalityCode and street name', function (t) {
new RealEstatValuation({ municipalityCode: 173, streetName: 'Lyngby Hovedgade' })
.once('data', function (item) {
t.ok(isNumber(item.id), 'id is number');
t.ok(isString(item.houseNumber), 'house number is string');
t.ok(isString(item.floor), 'floor is string');
t.ok(isString(item.type), 'type is string');
t.ok(isNumber(item.landValue), 'land value is number');
t.ok(isNumber(item.houseValue), 'house value is number');
t.end();
});
});
test('correct municipalityCode and street code', function (t) {
new RealEstatValuation({ municipalityCode: 173, streetCode: 535 })
.once('data', function (item) {
t.ok(isNumber(item.id), 'id is number');
t.ok(isString(item.houseNumber), 'house number is string');
t.ok(isString(item.floor), 'floor is string');
t.ok(isString(item.type), 'type is string');
t.ok(isNumber(item.landValue), 'land value is number');
t.ok(isNumber(item.houseValue), 'house value is number');
t.end();
});
});
test('missing area code', function (t) {
try {
new RealEstatValuation({ streetName: 'Lyngby Hovedgade' });
} catch(err) {
t.equal(err.name, 'TypeError');
t.equal(err.message, 'either zipcode or the municipality code should be set');
t.end();
}
});
test('missing steet name', function (t) {
try {
new RealEstatValuation({ zipCode: 2800 });
} catch(err) {
t.equal(err.name, 'TypeError');
t.equal(err.message, 'the steet name or code should be set');
t.end();
}
});
test('correct zipCode and street code', function (t) {
try {
new RealEstatValuation({ zipCode: 2800, streetCode: 535 });
} catch(err) {
t.equal(err.name, 'TypeError');
t.equal(err.message, 'the steet name or code should be set');
t.end();
}
});
test('incorrect zipcode', function (t) {
new RealEstatValuation({ zipCode: 1, streetName: 'Lyngby Hovedgade' })
.pipe(endpoint({objectMode: true}, function (err, evaluations) {
t.equal(err.name, 'Error');
t.equal(err.message, 'Fejl i POSTNR, indtast korrekt 4-cifret postnummer');
t.equal(evaluations.length, 0);
t.end();
}));
});
test('incorrect streetname', function (t) {
new RealEstatValuation({ zipCode: 2800, streetName: 'WRONG' })
.pipe(endpoint({objectMode: true}, function (err, evaluations) {
t.equal(err.name, 'Error');
t.equal(err.message, 'Vælg et vejnavn fra listen over vejnavne');
t.equal(evaluations.length, 0);
t.end();
}));
});