@datocms/rest-client-utils
Version:
Utilities for DatoCMS REST API clients
102 lines • 2.76 kB
JavaScript
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());
});
};
import { buildNormalizedParams } from '../buildNormalizedParams.js';
describe('buildNormalizedParams', () => {
it('encodes complex params', () => __awaiter(void 0, void 0, void 0, function* () {
expect(buildNormalizedParams({ foo: 0 })).toMatchInlineSnapshot(`
[
[
"foo",
"0",
],
]
`);
expect(buildNormalizedParams({ foo: true })).toMatchInlineSnapshot(`
[
[
"foo",
"true",
],
]
`);
expect(buildNormalizedParams({ foo: false })).toMatchInlineSnapshot(`
[
[
"foo",
"false",
],
]
`);
expect(buildNormalizedParams({ foo: '' })).toMatchInlineSnapshot(`
[
[
"foo",
"",
],
]
`);
expect(buildNormalizedParams({ foo: null })).toMatchInlineSnapshot('[]');
expect(buildNormalizedParams({ foo: undefined })).toMatchInlineSnapshot('[]');
expect(buildNormalizedParams({ foo: 'bàr' })).toMatchInlineSnapshot(`
[
[
"foo",
"bàr",
],
]
`);
expect(buildNormalizedParams({
page: {
offset: 0,
limit: 10,
},
})).toMatchInlineSnapshot(`
[
[
"page[offset]",
"0",
],
[
"page[limit]",
"10",
],
]
`);
expect(buildNormalizedParams({
filter: { fields: { md5: { eq: 'foo' } } },
})).toMatchInlineSnapshot(`
[
[
"filter[fields][md5][eq]",
"foo",
],
]
`);
expect(buildNormalizedParams({
foo: { bar: ['a', 'b', 10] },
})).toMatchInlineSnapshot(`
[
[
"foo[bar][]",
"a",
],
[
"foo[bar][]",
"b",
],
[
"foo[bar][]",
"10",
],
]
`);
}));
});
//# sourceMappingURL=buildNormalizedParams.test.js.map