|
| 1 | +import getListingChanges from "../getListingChanges"; |
| 2 | + |
| 3 | +import { mockListingData } from "../../test-utils"; |
| 4 | + |
| 5 | +describe("getListingChanges", () => { |
| 6 | + test("sets images", () => { |
| 7 | + const changes = getListingChanges( |
| 8 | + { banner_urls: true }, |
| 9 | + mockListingData, |
| 10 | + Object.assign(mockListingData, { |
| 11 | + banner: null, |
| 12 | + banner_urls: ["https://example.com/banner"], |
| 13 | + icon: null, |
| 14 | + icon_url: "https://example.com/icon", |
| 15 | + screenshot_urls: ["https://example.com/screenshot"], |
| 16 | + screenshots: null, |
| 17 | + }), |
| 18 | + ); |
| 19 | + |
| 20 | + expect(changes.images).toBeDefined(); |
| 21 | + |
| 22 | + if (changes.images) { |
| 23 | + expect(changes.images).toHaveLength(3); |
| 24 | + expect(changes.images[0].url).toEqual("https://example.com/banner"); |
| 25 | + expect(changes.images[0].type).toEqual("banner"); |
| 26 | + expect(changes.images[0].status).toEqual("uploaded"); |
| 27 | + |
| 28 | + expect(changes.images[1].url).toEqual("https://example.com/icon"); |
| 29 | + expect(changes.images[1].type).toEqual("icon"); |
| 30 | + expect(changes.images[1].status).toEqual("uploaded"); |
| 31 | + |
| 32 | + expect(changes.images[2].url).toEqual("https://example.com/screenshot"); |
| 33 | + expect(changes.images[2].type).toEqual("screenshot"); |
| 34 | + expect(changes.images[2].status).toEqual("uploaded"); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + test("sets contacts links", () => { |
| 39 | + const changes = getListingChanges( |
| 40 | + { contacts: true }, |
| 41 | + mockListingData, |
| 42 | + Object.assign(mockListingData, { |
| 43 | + contacts: [{ url: "https://example.com/contact" }], |
| 44 | + donations: [], |
| 45 | + issues: [], |
| 46 | + source_code: [], |
| 47 | + websites: [], |
| 48 | + }), |
| 49 | + ); |
| 50 | + |
| 51 | + expect(changes.links).toBeDefined(); |
| 52 | + |
| 53 | + if (changes.links) { |
| 54 | + expect(changes.links.contact).toHaveLength(1); |
| 55 | + expect(changes.links.contact[0]).toEqual("https://example.com/contact"); |
| 56 | + } |
| 57 | + }); |
| 58 | + |
| 59 | + test("sets donations links", () => { |
| 60 | + const changes = getListingChanges( |
| 61 | + { donations: true }, |
| 62 | + mockListingData, |
| 63 | + Object.assign(mockListingData, { |
| 64 | + contacts: [], |
| 65 | + donations: [{ url: "https://example.com/donations" }], |
| 66 | + issues: [], |
| 67 | + source_code: [], |
| 68 | + websites: [], |
| 69 | + }), |
| 70 | + ); |
| 71 | + |
| 72 | + expect(changes.links).toBeDefined(); |
| 73 | + |
| 74 | + if (changes.links) { |
| 75 | + expect(changes.links.donations).toHaveLength(1); |
| 76 | + expect(changes.links.donations[0]).toEqual( |
| 77 | + "https://example.com/donations", |
| 78 | + ); |
| 79 | + } |
| 80 | + }); |
| 81 | + |
| 82 | + test("sets issues links", () => { |
| 83 | + const changes = getListingChanges( |
| 84 | + { issues: true }, |
| 85 | + mockListingData, |
| 86 | + Object.assign(mockListingData, { |
| 87 | + contacts: [], |
| 88 | + donations: [], |
| 89 | + issues: [{ url: "https://example.com/issues" }], |
| 90 | + source_code: [], |
| 91 | + websites: [], |
| 92 | + }), |
| 93 | + ); |
| 94 | + |
| 95 | + expect(changes.links).toBeDefined(); |
| 96 | + |
| 97 | + if (changes.links) { |
| 98 | + expect(changes.links.issues).toHaveLength(1); |
| 99 | + expect(changes.links.issues[0]).toEqual("https://example.com/issues"); |
| 100 | + } |
| 101 | + }); |
| 102 | + |
| 103 | + test("sets source_code links", () => { |
| 104 | + const changes = getListingChanges( |
| 105 | + { source_code: true }, |
| 106 | + mockListingData, |
| 107 | + Object.assign(mockListingData, { |
| 108 | + contacts: [], |
| 109 | + donations: [], |
| 110 | + issues: [], |
| 111 | + source_code: [{ url: "https://example.com/source" }], |
| 112 | + websites: [], |
| 113 | + }), |
| 114 | + ); |
| 115 | + |
| 116 | + expect(changes.links).toBeDefined(); |
| 117 | + |
| 118 | + if (changes.links) { |
| 119 | + expect(changes.links.source).toHaveLength(1); |
| 120 | + expect(changes.links.source[0]).toEqual("https://example.com/source"); |
| 121 | + } |
| 122 | + }); |
| 123 | + |
| 124 | + test("sets websites links", () => { |
| 125 | + const changes = getListingChanges( |
| 126 | + { websites: true }, |
| 127 | + mockListingData, |
| 128 | + Object.assign(mockListingData, { |
| 129 | + contacts: [], |
| 130 | + donations: [], |
| 131 | + issues: [], |
| 132 | + primary_website: "", |
| 133 | + source_code: [], |
| 134 | + websites: [ |
| 135 | + { url: "https://example.com/primary" }, |
| 136 | + { url: "https://example.com/secondary" }, |
| 137 | + ], |
| 138 | + }), |
| 139 | + ); |
| 140 | + |
| 141 | + expect(changes.links).toBeDefined(); |
| 142 | + |
| 143 | + if (changes.links) { |
| 144 | + expect(changes.links.website).toHaveLength(2); |
| 145 | + expect(changes.links.website[0]).toEqual("https://example.com/primary"); |
| 146 | + expect(changes.links.website[1]).toEqual("https://example.com/secondary"); |
| 147 | + } |
| 148 | + }); |
| 149 | + |
| 150 | + test("sets description", () => { |
| 151 | + const changes = getListingChanges( |
| 152 | + { description: true }, |
| 153 | + mockListingData, |
| 154 | + Object.assign(mockListingData, { description: "Test description" }), |
| 155 | + ); |
| 156 | + |
| 157 | + expect(changes.description).toEqual("Test description"); |
| 158 | + }); |
| 159 | + |
| 160 | + test("sets summary", () => { |
| 161 | + const changes = getListingChanges( |
| 162 | + { summary: true }, |
| 163 | + mockListingData, |
| 164 | + Object.assign(mockListingData, { summary: "Test summary" }), |
| 165 | + ); |
| 166 | + |
| 167 | + expect(changes.summary).toEqual("Test summary"); |
| 168 | + }); |
| 169 | + |
| 170 | + test("sets title", () => { |
| 171 | + const changes = getListingChanges( |
| 172 | + { title: true }, |
| 173 | + mockListingData, |
| 174 | + Object.assign(mockListingData, { title: "Test title" }), |
| 175 | + ); |
| 176 | + |
| 177 | + expect(changes.title).toEqual("Test title"); |
| 178 | + }); |
| 179 | + |
| 180 | + test("sets primary category", () => { |
| 181 | + const changes = getListingChanges( |
| 182 | + { |
| 183 | + primary_category: true, |
| 184 | + }, |
| 185 | + mockListingData, |
| 186 | + Object.assign(mockListingData, { |
| 187 | + primary_category: "test-primary-category", |
| 188 | + secondary_category: "", |
| 189 | + }), |
| 190 | + ); |
| 191 | + |
| 192 | + expect(changes.categories).toBeDefined(); |
| 193 | + |
| 194 | + if (changes.categories) { |
| 195 | + expect(changes.categories).toHaveLength(1); |
| 196 | + expect(changes.categories[0]).toEqual("test-primary-category"); |
| 197 | + } |
| 198 | + }); |
| 199 | + |
| 200 | + test("sets secondary category", () => { |
| 201 | + const changes = getListingChanges( |
| 202 | + { |
| 203 | + secondary_category: true, |
| 204 | + }, |
| 205 | + mockListingData, |
| 206 | + Object.assign(mockListingData, { |
| 207 | + primary_category: "", |
| 208 | + secondary_category: "test-secondary-category", |
| 209 | + }), |
| 210 | + ); |
| 211 | + |
| 212 | + expect(changes.categories).toBeDefined(); |
| 213 | + |
| 214 | + if (changes.categories) { |
| 215 | + expect(changes.categories).toHaveLength(1); |
| 216 | + expect(changes.categories[0]).toEqual("test-secondary-category"); |
| 217 | + } |
| 218 | + }); |
| 219 | + |
| 220 | + test("sets primary and secondary category", () => { |
| 221 | + const changes = getListingChanges( |
| 222 | + { |
| 223 | + primary_category: true, |
| 224 | + secondary_category: true, |
| 225 | + }, |
| 226 | + mockListingData, |
| 227 | + Object.assign(mockListingData, { |
| 228 | + primary_category: "test-primary-category", |
| 229 | + secondary_category: "test-secondary-category", |
| 230 | + }), |
| 231 | + ); |
| 232 | + |
| 233 | + expect(changes.categories).toBeDefined(); |
| 234 | + |
| 235 | + if (changes.categories) { |
| 236 | + expect(changes.categories).toHaveLength(2); |
| 237 | + expect(changes.categories[0]).toEqual("test-primary-category"); |
| 238 | + expect(changes.categories[1]).toEqual("test-secondary-category"); |
| 239 | + } |
| 240 | + }); |
| 241 | + |
| 242 | + test("sets public_metrics_blacklist if only territories", () => { |
| 243 | + const changes = getListingChanges( |
| 244 | + { public_metrics_distros: true, public_metrics_territories: true }, |
| 245 | + mockListingData, |
| 246 | + Object.assign(mockListingData, { |
| 247 | + public_metrics_distros: false, |
| 248 | + public_metrics_territories: true, |
| 249 | + }), |
| 250 | + ); |
| 251 | + |
| 252 | + expect(changes.public_metrics_blacklist).toBeDefined(); |
| 253 | + |
| 254 | + if (changes.public_metrics_blacklist) { |
| 255 | + expect(changes.public_metrics_blacklist).toHaveLength(1); |
| 256 | + expect(changes.public_metrics_blacklist[0]).toEqual( |
| 257 | + "weekly_installed_base_by_operating_system_normalized", |
| 258 | + ); |
| 259 | + } |
| 260 | + }); |
| 261 | + |
| 262 | + test("sets public_metrics_blacklist if distros", () => { |
| 263 | + const changes = getListingChanges( |
| 264 | + { public_metrics_distros: true, public_metrics_territories: true }, |
| 265 | + mockListingData, |
| 266 | + Object.assign(mockListingData, { |
| 267 | + public_metrics_distros: true, |
| 268 | + public_metrics_territories: false, |
| 269 | + }), |
| 270 | + ); |
| 271 | + |
| 272 | + expect(changes.public_metrics_blacklist).toBeDefined(); |
| 273 | + |
| 274 | + if (changes.public_metrics_blacklist) { |
| 275 | + expect(changes.public_metrics_blacklist).toHaveLength(1); |
| 276 | + expect(changes.public_metrics_blacklist[0]).toEqual( |
| 277 | + "installed_base_by_country_percent", |
| 278 | + ); |
| 279 | + } |
| 280 | + }); |
| 281 | + |
| 282 | + test("sets public_metrics_blacklist if territories and distros", () => { |
| 283 | + const changes = getListingChanges( |
| 284 | + { public_metrics_distros: true, public_metrics_territories: true }, |
| 285 | + mockListingData, |
| 286 | + Object.assign(mockListingData, { |
| 287 | + public_metrics_distros: true, |
| 288 | + public_metrics_territories: true, |
| 289 | + }), |
| 290 | + ); |
| 291 | + |
| 292 | + expect(changes.public_metrics_blacklist).toBeDefined(); |
| 293 | + |
| 294 | + if (changes.public_metrics_blacklist) { |
| 295 | + expect(changes.public_metrics_blacklist).toHaveLength(0); |
| 296 | + } |
| 297 | + }); |
| 298 | + |
| 299 | + test("sets public_metrics_blacklist if not territories or distros", () => { |
| 300 | + const changes = getListingChanges( |
| 301 | + { public_metrics_distros: true, public_metrics_territories: true }, |
| 302 | + mockListingData, |
| 303 | + Object.assign(mockListingData, { |
| 304 | + public_metrics_distros: false, |
| 305 | + public_metrics_territories: false, |
| 306 | + }), |
| 307 | + ); |
| 308 | + |
| 309 | + expect(changes.public_metrics_blacklist).toBeDefined(); |
| 310 | + |
| 311 | + if (changes.public_metrics_blacklist) { |
| 312 | + expect(changes.public_metrics_blacklist).toHaveLength(2); |
| 313 | + expect(changes.public_metrics_blacklist[0]).toEqual( |
| 314 | + "installed_base_by_country_percent", |
| 315 | + ); |
| 316 | + expect(changes.public_metrics_blacklist[1]).toEqual( |
| 317 | + "weekly_installed_base_by_operating_system_normalized", |
| 318 | + ); |
| 319 | + } |
| 320 | + }); |
| 321 | +}); |
0 commit comments