Last active
February 4, 2026 21:58
-
-
Save JeffJacobson/440306e700a17d8fb914a02aa145c66e to your computer and use it in GitHub Desktop.
Display FeatureSet as a Table - Postman - Post Response Visualization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @typedef SpatialReference | |
| * @property {number} wkid | |
| * @property {?number} latestWkid | |
| */ | |
| /** | |
| * @typedef Field | |
| * @property {string} name | |
| * @property {string} type | |
| * @property {string} alias | |
| * @property {number?} length | |
| */ | |
| /** | |
| * @typedef Point | |
| * @property {number} x | |
| * @property {number} y | |
| */ | |
| /** | |
| * @typedef Polyline | |
| * @property {[number, number][][]} paths | |
| */ | |
| /** | |
| * @typedef {(Point|Polyline)} Geometry | |
| */ | |
| /** | |
| * @typedef Feature | |
| * @property {Object.<string, *>} attributes | |
| * @property {Geometry} geometry | |
| */ | |
| /** | |
| * @typedef FeatureSet | |
| * @property {string} displayFieldName | |
| * @property {Object.<string, string>} fieldAliases - A mapping of field names to their aliases. | |
| * @property {"esriGeometryPoint"|"esriGeometryPolyline"} - geometry type | |
| * @property {SpatialReference} spatialReference | |
| * @property {Field[]} fields | |
| * @property {Feature[]} features | |
| * @property {?string} timestamp | |
| */ | |
| /** | |
| * @param {string} key | |
| * @param {*} value | |
| */ | |
| function convertJsonValues(key, value) { | |
| if (typeof value === "string") { | |
| if (key === "timestamp") { | |
| // 2022-09-01 15:06:38.088228 | |
| return new Date(value); | |
| } | |
| } | |
| else if (typeof value === "number") { | |
| if (key.match(/.*Date.*/i)) { | |
| // 1770229885060 | |
| return new Date(value); | |
| } | |
| } | |
| return value; | |
| } | |
| /** | |
| * @type {FeatureSet} | |
| */ | |
| const jsonData = pm.response.json(convertJsonValues); | |
| const maxMinutes = 5; | |
| pm.test(`Timestamp should be no more than ${maxMinutes} minutes old.`, function () { | |
| /** @type {Date} */ | |
| const timestamp = jsonData.timestamp; | |
| const now = new Date(); | |
| const elapsed = (now - timestamp) / (1000) / 60; | |
| console.log(`timestamp: ${timestamp}\nnow: ${now}\nelapsed${elapsed}`); | |
| pm.expect(elapsed).to.be.lte(maxMinutes); | |
| }); | |
| pm.test("Has expected attributes", () => { | |
| pm.expect(jsonData) | |
| .to.have.own.property("geometryType") | |
| .which.matches(/^esriGeometry((Point)|(Polyline))/) | |
| const arrayPropertyNames = ["features", "fields"] | |
| for (const fieldName of arrayPropertyNames) { | |
| pm.expect(jsonData) | |
| .to.have.own.property(fieldName) | |
| .instanceOf(Array) | |
| } | |
| for (const feature of jsonData.features) { | |
| pm.expect(feature).to.have.own.property("attributes").to.be.an("object"); | |
| pm.expect(feature).to.have.own.property("geometry").to.be.an("object"); | |
| } | |
| }) | |
| const template = ` | |
| <style> | |
| body { | |
| background-color: white; | |
| color: black; | |
| } | |
| table { | |
| border-collapse: collapse; | |
| } | |
| td { | |
| border: 1px solid black; | |
| } | |
| tr { | |
| padding: 0; | |
| } | |
| </style> | |
| {{#with response}} | |
| {{#if timestamp}} | |
| <p>Last updated: {{timestamp}}</p> | |
| {{/if}} | |
| <table> | |
| <thead> | |
| <tr> | |
| {{#each fields}} | |
| <th>{{alias}}</th> | |
| {{/each}} | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {{#each features}} | |
| <tr> | |
| {{#each attributes}} | |
| <td> | |
| {{this}} | |
| </td> | |
| {{/each}} | |
| </tr> | |
| {{/each}} | |
| </tbody> | |
| </table> | |
| {{/with}} | |
| ` | |
| pm.visualizer.set(template, { | |
| response: jsonData | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment