Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amplify-frontend-javascript): geo region default (#8552)
- Loading branch information
1 parent
1da86c2
commit 60255ee
Showing
3 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ages/amplify-frontend-javascript/tests/__snapshots__/frontend-config-creator.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
], | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
91 changes: 91 additions & 0 deletions
91
packages/amplify-frontend-javascript/tests/frontend-config-creator.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |