Skip to content

Commit a58cfd2

Browse files
authored
Merge pull request #10 from joelfsreis/fix/search-by-language-code-and-expose-manifest-timestamp
Fix/search by language code and expose manifest timestamp
2 parents ed49d12 + fb17487 commit a58cfd2

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ export default class OtaClient {
102102
return this.locale;
103103
}
104104

105+
/**
106+
* Get manifest timestamp of distribution
107+
*/
108+
async getManifestTimestamp(): Promise<number> {
109+
return (await this.manifest).timestamp;
110+
}
111+
105112
/**
106113
* List of files in distribution
107114
*/

src/internal/util/exportPattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2729,7 +2729,7 @@ export function includesLanguagePlaceholders(str: string): boolean {
27292729
}
27302730

27312731
export function replaceLanguagePlaceholders(str: string, languageCode: string): string {
2732-
const language = languages.find(l => l.twoLettersCode === languageCode);
2732+
const language = languages.find(l => l.twoLettersCode === languageCode || l.locale === languageCode);
27332733
if (!language) {
27342734
throw new Error(`Unsupported language code : ${languageCode}`);
27352735
}

tests/index.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as nock from 'nock';
22
import OtaClient, { Manifest } from '../src/index';
33

44
describe('OTA client', () => {
5+
const now = Date.now();
56
let scope: nock.Scope;
67
const languageCode = 'uk';
78
const hash = 'testHash';
@@ -13,7 +14,7 @@ describe('OTA client', () => {
1314
const manifest: Manifest = {
1415
files: [filePath],
1516
languages: [languageCode],
16-
timestamp: Date.now(),
17+
timestamp: now,
1718
};
1819
const jsonFilePath1 = '/folder/file1.json';
1920
const jsonFilePath2 = '/folder/file2.json';
@@ -30,7 +31,7 @@ describe('OTA client', () => {
3031
const manifestWithJsonFiles: Manifest = {
3132
files: [jsonFilePath1, jsonFilePath2],
3233
languages: [languageCode],
33-
timestamp: Date.now(),
34+
timestamp: now,
3435
};
3536

3637
beforeAll(() => {
@@ -62,6 +63,12 @@ describe('OTA client', () => {
6263
expect(client.getCurrentLocale()).toBe(languageCode);
6364
});
6465

66+
it('should return manifest timestamp', async () => {
67+
const timestamp = await client.getManifestTimestamp();
68+
expect(timestamp).toEqual(manifest.timestamp);
69+
expect(timestamp).toEqual(now);
70+
});
71+
6572
it('should return list of files from manifest', async () => {
6673
const files = await client.listFiles();
6774
expect(files).toEqual(manifest.files);

tests/internal/util/exportPattern.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ describe('Export Pattern Util', () => {
1313
const str2 = '/%language%/%two_letters_code%/file2.csv';
1414
const str3 = '/%locale_with_underscore%/%android_code%/file3.csv';
1515
const str4 = '/%osx_code%/%osx_locale%/file4.csv';
16+
const str5 = '/%language%/%two_letters_code%/%locale%/file5.csv';
17+
const str6 = '/%language%/%locale_with_underscore%/%two_letters_code%/%locale%/file6.csv';
1618
expect(replaceLanguagePlaceholders(str1, 'uk')).toBe('/folder/uk-UA/ukr/file1.csv');
1719
expect(replaceLanguagePlaceholders(str2, 'es')).toBe('/Spanish/es/file2.csv');
1820
expect(replaceLanguagePlaceholders(str3, 'en')).toBe('/en_US/en-rUS/file3.csv');
1921
expect(replaceLanguagePlaceholders(str4, 'de')).toBe('/de.lproj/de/file4.csv');
22+
expect(replaceLanguagePlaceholders(str5, 'es-US')).toBe('/Spanish, United States/es/es-US/file5.csv');
23+
expect(replaceLanguagePlaceholders(str6, 'en-GB')).toBe('/English, United Kingdom/en_GB/en/en-GB/file6.csv');
2024
});
2125

2226
it('should throw error for invalid language code', () => {
2327
expect(() => replaceLanguagePlaceholders('test', 'invalidLang')).toThrowError();
28+
expect(() => replaceLanguagePlaceholders('test', 'pt-PT')).not.toThrowError();
2429
});
2530
});

0 commit comments

Comments
 (0)