@datocms/rest-client-utils
Version:
Utilities for DatoCMS REST API clients
104 lines • 3.16 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const buildNormalizedParams_js_1 = require("../buildNormalizedParams.js");
describe('buildNormalizedParams', () => {
it('encodes complex params', () => __awaiter(void 0, void 0, void 0, function* () {
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({ foo: 0 })).toMatchInlineSnapshot(`
[
[
"foo",
"0",
],
]
`);
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({ foo: true })).toMatchInlineSnapshot(`
[
[
"foo",
"true",
],
]
`);
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({ foo: false })).toMatchInlineSnapshot(`
[
[
"foo",
"false",
],
]
`);
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({ foo: '' })).toMatchInlineSnapshot(`
[
[
"foo",
"",
],
]
`);
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({ foo: null })).toMatchInlineSnapshot('[]');
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({ foo: undefined })).toMatchInlineSnapshot('[]');
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({ foo: 'bàr' })).toMatchInlineSnapshot(`
[
[
"foo",
"bàr",
],
]
`);
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({
page: {
offset: 0,
limit: 10,
},
})).toMatchInlineSnapshot(`
[
[
"page[offset]",
"0",
],
[
"page[limit]",
"10",
],
]
`);
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({
filter: { fields: { md5: { eq: 'foo' } } },
})).toMatchInlineSnapshot(`
[
[
"filter[fields][md5][eq]",
"foo",
],
]
`);
expect((0, buildNormalizedParams_js_1.buildNormalizedParams)({
foo: { bar: ['a', 'b', 10] },
})).toMatchInlineSnapshot(`
[
[
"foo[bar][]",
"a",
],
[
"foo[bar][]",
"b",
],
[
"foo[bar][]",
"10",
],
]
`);
}));
});
//# sourceMappingURL=buildNormalizedParams.test.js.map