Skip to content

Commit

Permalink
[Console] Convert lib/mappings to TypeScript (#4008) (#4500)
Browse files Browse the repository at this point in the history
* Convert mappings.js to TypeScript

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Convert mappings.test.js to TypeScript

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Update CHANGELOG.md

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Add test for getTypes with multi-index mode

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* type update

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* update typing

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* CHANGELOG fix

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Changelog update

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Update Changelog

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

---------

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>
Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Signed-off-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Kawika Avilla <kavilla414@gmail.com>
Co-authored-by: Qingyang(Abby) Hu <abigailhu2000@gmail.com>
Co-authored-by: Ashwin P Chandran <ashwinpc@amazon.com>
Co-authored-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
(cherry picked from commit e07c5e6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent e079fde commit 0331696
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

import { Field } from '../mappings';
import '../../../application/models/sense_editor/sense_editor.test.mocks';
import * as mappings from '../mappings';

Expand All @@ -39,7 +40,7 @@ describe('Mappings', () => {
mappings.clear();
});

function fc(f1, f2) {
function fc(f1: Field, f2: Field) {
if (f1.name < f2.name) {
return -1;
}
Expand All @@ -49,8 +50,8 @@ describe('Mappings', () => {
return 0;
}

function f(name, type) {
return { name: name, type: type || 'string' };
function f(name: string, type?: string) {
return { name, type: type || 'string' };
}

test('Multi fields 1.0 style', function () {
Expand Down Expand Up @@ -256,10 +257,37 @@ describe('Mappings', () => {
'test_index2',
]);
expect(mappings.getIndices(false).sort()).toEqual(['test_index1', 'test_index2']);
expect(mappings.expandAliases(['alias1', 'test_index2']).sort()).toEqual([
expect((mappings.expandAliases(['alias1', 'test_index2']) as string[]).sort()).toEqual([
'test_index1',
'test_index2',
]);
expect(mappings.expandAliases('alias2')).toEqual('test_index2');
});

test('Multi types', function () {
mappings.loadMappings({
index: {
properties: {
name1: {
type: 'object',
path: 'just_name',
properties: {
first1: { type: 'string' },
last1: { type: 'string', index_name: 'i_last_1' },
},
},
name2: {
type: 'object',
path: 'full',
properties: {
first2: { type: 'string' },
last2: { type: 'string', index_name: 'i_last_2' },
},
},
},
},
});

expect(mappings.getTypes()).toEqual(['properties']);
});
});
Loading

0 comments on commit 0331696

Please sign in to comment.