Skip to content

Commit

Permalink
fix(amplify-frontend-javascript): geo region default (#8552)
Browse files Browse the repository at this point in the history
  • Loading branch information
phani-srikar committed Oct 26, 2021
1 parent 1da86c2 commit 60255ee
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 3 deletions.
Expand Up @@ -169,11 +169,11 @@ function getAWSExportsObject(resources) {
};
break;
case 'Map':
geoConfig.region = serviceResourceMapping[service][0].output.Region;
geoConfig.region = serviceResourceMapping[service][0].output.Region || projectRegion;
geoConfig.maps = getMapConfig(serviceResourceMapping[service]);
break;
case 'PlaceIndex':
geoConfig.region = serviceResourceMapping[service][0].output.Region;
geoConfig.region = serviceResourceMapping[service][0].output.Region || projectRegion;
geoConfig.search_indices = getPlaceIndexConfig(serviceResourceMapping[service]);
break;
default:
Expand Down Expand Up @@ -593,4 +593,4 @@ function getPlaceIndexConfig(placeIndexResources) {
return placeIndexConfig;
}

module.exports = { createAWSExports, createAmplifyConfig, deleteAmplifyConfig };
module.exports = { createAWSExports, createAmplifyConfig, deleteAmplifyConfig, getAWSExportsObject };
@@ -0,0 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generate maps and search configuration generates correct configuration for maps and search geo resources with Region as CFN output 1`] = `
Object {
"aws_project_region": "eu-west-2",
"geo": Object {
"amazon_location_service": Object {
"maps": Object {
"default": "defaultMap12345",
"items": Object {
"defaultMap12345": Object {
"style": "VectorEsriStreets",
},
"map12345": Object {
"style": "VectorEsriStreets",
},
},
},
"region": "eu-west-1",
"search_indices": Object {
"default": "defaultIndex12345",
"items": Array [
"index12345",
"defaultIndex12345",
],
},
},
},
}
`;

exports[`generate maps and search configuration generates correct configuration for maps and search geo resources without Region CFN output 1`] = `
Object {
"aws_project_region": "us-west-2",
"geo": Object {
"amazon_location_service": Object {
"maps": Object {
"default": "defaultMap12345",
"items": Object {
"defaultMap12345": Object {
"style": "VectorEsriStreets",
},
"map12345": Object {
"style": "VectorEsriStreets",
},
},
},
"region": "us-west-2",
"search_indices": Object {
"default": "defaultIndex12345",
"items": Array [
"index12345",
"defaultIndex12345",
],
},
},
},
}
`;
@@ -0,0 +1,91 @@
const configCreator = require("../lib/frontend-config-creator");
jest.mock('amplify-cli-core');

const mapServiceName = 'Map';
const placeIndexServiceName = 'PlaceIndex';

describe('generate maps and search configuration', () => {

function constructMapMeta(mapName, mapStyle, isDefault, region) {
return {
service: mapServiceName,
output: {
Style: mapStyle,
Name: mapName,
Region: region
},
isDefault: isDefault
};
}

function constructPlaceIndexMeta(indexName, isDefault, region) {
return {
service: placeIndexServiceName,
output: {
Name: indexName,
Region: region
},
isDefault: isDefault
};
}

beforeEach(() => {
jest.clearAllMocks();
});

it('generates correct configuration for maps and search geo resources without Region CFN output', () => {
const projectRegion = 'us-west-2';
const mockGeoResources = {
serviceResourceMapping: {
Map: [
constructMapMeta('map12345', 'VectorEsriStreets', false),
constructMapMeta('defaultMap12345', 'VectorEsriStreets', true)
],
PlaceIndex: [
constructPlaceIndexMeta('index12345', false),
constructPlaceIndexMeta('defaultIndex12345', true)
]
},
metadata: {
Region: projectRegion
}
};
const generatedConfig = configCreator.getAWSExportsObject(mockGeoResources);
expect(generatedConfig.geo.amazon_location_service.region).toEqual(projectRegion);
expect(generatedConfig).toMatchSnapshot();
});

it('does not add any geo configuration if no maps or search is added', () => {
const mockGeoResources = {
serviceResourceMapping: {},
metadata: {
Region: 'us-west-2'
}
};
const generatedConfig = configCreator.getAWSExportsObject(mockGeoResources);
expect(generatedConfig.geo).toBeUndefined();
});

it('generates correct configuration for maps and search geo resources with Region as CFN output', () => {
const resourceRegion = 'eu-west-1';
const projectRegion = 'eu-west-2';
const mockGeoResources = {
serviceResourceMapping: {
Map: [
constructMapMeta('map12345', 'VectorEsriStreets', false, resourceRegion),
constructMapMeta('defaultMap12345', 'VectorEsriStreets', true, resourceRegion)
],
PlaceIndex: [
constructPlaceIndexMeta('index12345', false, resourceRegion),
constructPlaceIndexMeta('defaultIndex12345', true, resourceRegion)
]
},
metadata: {
Region: projectRegion
}
};
const generatedConfig = configCreator.getAWSExportsObject(mockGeoResources);
expect(generatedConfig.geo.amazon_location_service.region).toEqual(resourceRegion);
expect(generatedConfig).toMatchSnapshot();
});
});

0 comments on commit 60255ee

Please sign in to comment.