Skip to content

Commit

Permalink
feat: add csp and suggest_apikey options to YaConfig (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddubrava committed Nov 18, 2023
1 parent f4c199a commit 98c9adf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 9 additions & 1 deletion libs/angular8-yandex-maps/src/lib/interfaces/ya-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
*/
export interface YaConfig {
/**
* API key. You can get a key in the developer's dashboard.
* API key.
*/
apikey?: string;
/**
* Geosuggest API key.
*/
suggest_apikey?: string;
/**
* Locale.
*/
Expand All @@ -22,6 +26,10 @@ export interface YaConfig {
* API loading mode.
*/
mode?: 'release' | 'debug';
/**
* Enables CSP mode.
*/
csp?: boolean;
/**
* Use commercial version of the API.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ describe('YaApiLoaderService', () => {
mockLoaderService(config);

service.load().subscribe(() => {
expect(script.src).toContain('https://api-maps.yandex.ru');
expect(script.src).toContain('2.1');
expect(script.src).toContain('apikey=X-X-X');
expect(script.src).toContain('lang=ru_RU');
expect(script.src).toBe('https://api-maps.yandex.ru/2.1/?lang=ru_RU&apikey=X-X-X');
done();
});

Expand All @@ -129,23 +126,23 @@ describe('YaApiLoaderService', () => {
it('should create script with provided options if config is passed', (done) => {
const config: YaConfig = {
apikey: 'X-X-X',
suggest_apikey: 'Y-Y-Y',
lang: 'en_US',
coordorder: 'latlong',
load: 'package.full',
mode: 'release',
csp: true,
version: '2.0',
};

mockLoaderService(config);

service.load().subscribe(() => {
expect(script.src).toContain('https://api-maps.yandex.ru');
expect(script.src).toContain('2.0');
expect(script.src).toContain('apikey=X-X-X');
expect(script.src).toContain('lang=en_US');
expect(script.src).toContain('coordorder=latlong');
expect(script.src).toContain('load=package.full');
expect(script.src).toContain('mode=release');
// They are not in the same order as YaConfig, since there is a default config.
expect(script.src).toBe(
'https://api-maps.yandex.ru/2.0/?lang=en_US&apikey=X-X-X&suggest_apikey=Y-Y-Y&coordorder=latlong&load=package.full&mode=release&csp=true',
);

done();
});

Expand Down

0 comments on commit 98c9adf

Please sign in to comment.