Skip to content

Commit

Permalink
feat(amplify-appsync-simulator): map.keySet returns an a JavaArray wi…
Browse files Browse the repository at this point in the history
…th elements of type JavaString
  • Loading branch information
alichherawalla committed Jul 2, 2021
1 parent 9b8ab5a commit f7f2c66
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { JavaArray } from './../../../velocity/value-mapper/array';
import { JavaMap } from '../../../velocity/value-mapper/map';
import { JavaString } from '../../../velocity/value-mapper/string';
import { map as mapper } from '../../../velocity/value-mapper/mapper';

describe('JavaMap', () => {
let identityMapper = jest.fn().mockImplementation(val => val);
Expand Down Expand Up @@ -36,7 +39,10 @@ describe('JavaMap', () => {
it('entrySet', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.entrySet().toJSON()).toEqual([{ key: 'foo', value: 'Foo Value' }, { key: 'bar', value: 'Bar Value' }]);
expect(map.entrySet().toJSON()).toEqual([
{ key: 'foo', value: 'Foo Value' },
{ key: 'bar', value: 'Bar Value' },
]);
});

it('equal', () => {
Expand Down Expand Up @@ -66,6 +72,12 @@ describe('JavaMap', () => {
expect(map.keySet().toJSON()).toEqual(['foo', 'bar']);
});

it('keySet returns a JavaArray with each element of type JavaString', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.keySet()).toEqual(new JavaArray([new JavaString('foo'), new JavaString('bar')], mapper));
});

it('put', () => {
const map = new JavaMap({}, identityMapper);
map.put('foo', 'Foo Value');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JavaString, toJavaString } from '../../../velocity/value-mapper/string';
import { JavaString } from '../../../velocity/value-mapper/string';

describe('JavaString', () => {
it('replaceAll', () => {
Expand Down Expand Up @@ -131,8 +131,4 @@ describe('JavaString', () => {
const str4 = new JavaString('foo bar ');
expect(str4.trim().toString()).toEqual('foo bar');
});
it('toJavaString', () => {
const str = toJavaString('foo bar');
expect(str instanceof JavaString).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { JavaString } from './string';
import { toJSON } from './to-json';

export class JavaArray extends Array<any> {
Expand All @@ -8,13 +7,6 @@ export class JavaArray extends Array<any> {
// splice sends a single object
values = [values];
}
values = values.map(value => {
if (typeof value === 'string' && !((value as any) instanceof JavaString)) {
return new JavaString(value);
}
return value;
});

if (values.length !== 1) {
super(...values);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JavaArray } from './array';
import { toJSON } from './to-json';
import { map } from './mapper';

export class JavaMap {
private map: Map<string, any>;
Expand Down Expand Up @@ -56,7 +57,7 @@ export class JavaMap {
}

keySet() {
return new JavaArray(Array.from(this.map.keys()), this.mapper);
return map(Array.from(this.map.keys()));
}

put(key, value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,3 @@ export class JavaString {
return this.value && this.value.length;
}
}
/**
* Mapper function to convert string to JavaString
*/
export const toJavaString = (value: string): JavaString => new JavaString(value);

0 comments on commit f7f2c66

Please sign in to comment.