|
1 | 1 | import { describe, it, expect } from "vitest"; |
2 | | -import { formatUserName, getUserDisplayName, normalizeUser } from "./users.helpers"; |
| 2 | +import { |
| 3 | + formatUserName, |
| 4 | + getUserDisplayName, |
| 5 | + normalizeAgreementUsers, |
| 6 | + normalizeCanUsers, |
| 7 | + normalizePortfolioUsers, |
| 8 | + normalizeProjectUsers, |
| 9 | + normalizeUser |
| 10 | +} from "./users.helpers"; |
3 | 11 |
|
4 | 12 | describe("formatUserName", () => { |
5 | 13 | // Already mixed-case — leave untouched |
@@ -134,3 +142,69 @@ describe("normalizeUser", () => { |
134 | 142 | expect(normalizeUser(user)).toEqual({ ...user, display_name: "Jane Doe" }); |
135 | 143 | }); |
136 | 144 | }); |
| 145 | + |
| 146 | +describe("embedded payload normalizers", () => { |
| 147 | + it("normalizes agreement string name arrays and team members", () => { |
| 148 | + expect( |
| 149 | + normalizeAgreementUsers({ |
| 150 | + division_directors: ["DAVE DIRECTOR"], |
| 151 | + team_leaders: ["CHRIS FORTUNATO"], |
| 152 | + team_members: [{ id: 1, full_name: "AMELIA POPHAM", email: "amelia@example.com" }] |
| 153 | + }) |
| 154 | + ).toEqual({ |
| 155 | + division_directors: ["Dave Director"], |
| 156 | + team_leaders: ["Chris Fortunato"], |
| 157 | + team_members: [ |
| 158 | + { id: 1, full_name: "AMELIA POPHAM", email: "amelia@example.com", display_name: "Amelia Popham" } |
| 159 | + ] |
| 160 | + }); |
| 161 | + }); |
| 162 | + |
| 163 | + it("normalizes project team leaders, team members, and division directors", () => { |
| 164 | + expect( |
| 165 | + normalizeProjectUsers({ |
| 166 | + division_directors: ["DIRECTOR DERREK"], |
| 167 | + team_leaders: [{ id: 1, full_name: "CHRIS FORTUNATO", email: "chris@example.com" }], |
| 168 | + team_members: [{ id: 2, full_name: "SYSTEM OWNER", email: "owner@example.com" }] |
| 169 | + }) |
| 170 | + ).toEqual({ |
| 171 | + division_directors: ["Director Derrek"], |
| 172 | + team_leaders: [ |
| 173 | + { id: 1, full_name: "CHRIS FORTUNATO", email: "chris@example.com", display_name: "Chris Fortunato" } |
| 174 | + ], |
| 175 | + team_members: [ |
| 176 | + { id: 2, full_name: "SYSTEM OWNER", email: "owner@example.com", display_name: "System Owner" } |
| 177 | + ] |
| 178 | + }); |
| 179 | + }); |
| 180 | + |
| 181 | + it("normalizes portfolio team leaders", () => { |
| 182 | + expect( |
| 183 | + normalizePortfolioUsers({ |
| 184 | + id: 1, |
| 185 | + team_leaders: [{ id: 1, full_name: "JANE SMITH", email: "jane@example.com" }] |
| 186 | + }) |
| 187 | + ).toEqual({ |
| 188 | + id: 1, |
| 189 | + team_leaders: [{ id: 1, full_name: "JANE SMITH", email: "jane@example.com", display_name: "Jane Smith" }] |
| 190 | + }); |
| 191 | + }); |
| 192 | + |
| 193 | + it("normalizes nested portfolio team leaders on CAN payloads", () => { |
| 194 | + expect( |
| 195 | + normalizeCanUsers({ |
| 196 | + id: 1, |
| 197 | + portfolio: { |
| 198 | + id: 2, |
| 199 | + team_leaders: [{ id: 1, full_name: "JOHN DOE", email: "john@example.com" }] |
| 200 | + } |
| 201 | + }) |
| 202 | + ).toEqual({ |
| 203 | + id: 1, |
| 204 | + portfolio: { |
| 205 | + id: 2, |
| 206 | + team_leaders: [{ id: 1, full_name: "JOHN DOE", email: "john@example.com", display_name: "John Doe" }] |
| 207 | + } |
| 208 | + }); |
| 209 | + }); |
| 210 | +}); |
0 commit comments