Skip to content

Commit 1fd3fd7

Browse files
committed
Adiciona testes e mocks de verificação de endereço e casos extremos
1 parent f96b98f commit 1fd3fd7

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

server/__mocks__/addresses.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
const addresses = [
2+
{
3+
id: 1,
4+
street: '123 Satellite Blvd',
5+
city: 'Space City',
6+
state: 'TX',
7+
zip: '12345',
8+
type: 'satellite'
9+
},
10+
{
11+
id: 2,
12+
street: '456 Non-Residential Rd',
13+
city: 'Business Town',
14+
state: 'CA',
15+
zip: '67890',
16+
type: 'non-residential'
17+
},
18+
{
19+
id: 3,
20+
street: '789 PO Box',
21+
city: 'Mailville',
22+
state: 'NY',
23+
zip: '10112',
24+
type: 'PO Box'
25+
}
26+
];
27+
28+
// Edge cases for address verification tests
29+
const addressEdgeCases = [
30+
{
31+
type: 'residential_house',
32+
input: { line1: 'residential house', zip: '11111' },
33+
expected: {
34+
deliverable: true,
35+
warning: null,
36+
revisedAddress: {
37+
line1: '1709 BRODERICK ST',
38+
line2: null,
39+
city: 'SAN FRANCISCO',
40+
state: 'CA',
41+
zip: '94115-2525'
42+
}
43+
}
44+
},
45+
{
46+
type: 'residential_highrise',
47+
input: { line1: 'residential highrise', zip: '11111' },
48+
expected: {
49+
deliverable: true,
50+
revisedAddress: {
51+
city: 'SAN FRANCISCO',
52+
line1: '660 KING ST UNIT 305',
53+
line2: null,
54+
state: 'CA',
55+
zip: '94107-1539'
56+
},
57+
warning: null
58+
}
59+
},
60+
{
61+
type: 'department_of_state',
62+
input: { line1: 'department of state', zip: '11111' },
63+
expected: {
64+
deliverable: true,
65+
revisedAddress: {
66+
city: 'DPO',
67+
line1: 'UNIT 8900 BOX 4301',
68+
line2: null,
69+
state: 'AE',
70+
zip: '09831-4301'
71+
},
72+
warning: null
73+
}
74+
},
75+
{
76+
type: 'military',
77+
input: { line1: 'military', zip: '11111' },
78+
expected: {
79+
deliverable: true,
80+
revisedAddress: {
81+
city: 'APO',
82+
line1: 'CMR 409 BOX 145',
83+
line2: null,
84+
state: 'AE',
85+
zip: '09053-0002'
86+
},
87+
warning: null
88+
}
89+
},
90+
{
91+
type: 'unnecessary_unit',
92+
input: { line1: 'unnecessary unit', zip: '11111' },
93+
expected: {
94+
deliverable: true,
95+
revisedAddress: {
96+
city: 'SAN FRANCISCO',
97+
line1: '1709 BRODERICK ST APT 505',
98+
line2: null,
99+
state: 'CA',
100+
zip: '94115-2525'
101+
},
102+
warning: 'Address may be deliverable but contains an unnecessary suite number'
103+
}
104+
},
105+
{
106+
type: 'po_box',
107+
input: { line1: 'po box', zip: '11111' },
108+
expected: {
109+
error: 'Post office boxes are not currently supported'
110+
}
111+
},
112+
{
113+
type: 'puerto_rico',
114+
input: { line1: 'puerto rico', zip: '11111' },
115+
expected: {
116+
error: 'Puerto Rico addresses are not currently supported'
117+
}
118+
},
119+
{
120+
type: 'commercial_building',
121+
input: { line1: 'deliverable', zip: '11111' },
122+
expected: {
123+
error: 'Non-residential addresses are not currently supported'
124+
}
125+
},
126+
{
127+
type: 'commercial_highrise',
128+
input: { line1: 'commercial highrise', zip: '11111' },
129+
expected: {
130+
error: 'Non-residential addresses are not currently supported'
131+
}
132+
},
133+
{
134+
type: 'undeliverable',
135+
input: { line1: 'undeliverable block match', zip: '11111' },
136+
expected: {
137+
error: 'Address is undeliverable'
138+
}
139+
}
140+
];
141+
142+
module.exports = { addresses, addressEdgeCases };

server/__tests__/integration/lob.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const request = require('supertest')
33
const axios = require('axios')
44
const express = require('express')
55
const apiRouter = require('../../api')
6+
const { addresses, addressEdgeCases } = require('../../__mocks__/addresses')
67

78
// Create a test application
89
const app = express()
@@ -508,3 +509,30 @@ describe('POST /api/lob/createLetter', () => {
508509
})
509510
})
510511
})
512+
513+
describe('POST /api/lob/addressVerification edge cases', () => {
514+
const route = '/api/lob/addressVerification'
515+
516+
// Test using addressEdgeCases
517+
addressEdgeCases.forEach(({ type, input, expected }) => {
518+
test(`handles edge case: ${type}`, async () => {
519+
const response = await request(app).post(route).send(input)
520+
if (expected.error) {
521+
expect(response.status).toBe(400)
522+
expect(response.body).toEqual(expected)
523+
} else {
524+
expect(response.status).toBe(200)
525+
expect(response.body).toEqual(expected)
526+
}
527+
})
528+
})
529+
530+
// Test using addresses (basic structure, can be expanded as needed)
531+
addresses.forEach(({ street, zip, type }) => {
532+
test(`handles mock address: ${type}`, async () => {
533+
const response = await request(app).post(route).send({ line1: street, zip })
534+
// Como addresses não tem expected, apenas verifica se retorna algum status (ajuste conforme necessário)
535+
expect([200, 400]).toContain(response.status)
536+
})
537+
})
538+
})

0 commit comments

Comments
 (0)