UNPKG

2.62 kBPlain TextView Raw
1/* tslint:disable:no-implicit-dependencies no-any */
2/**
3 * Index tests
4 */
5
6import test from "ava";
7import * as ScanditSDK from ".";
8
9test("configure", async t => {
10 // Set inside setupBrowserEnv.js
11 const baseUrl: string = "https://example.com/";
12 const baseDirectory: string = "file:///tmp/";
13
14 let error: Error = await t.throwsAsync(ScanditSDK.configure(""));
15 t.is(error.name, "UnsupportedBrowserError");
16
17 ScanditSDK.BrowserHelper.checkBrowserCompatibility = () => {
18 return {
19 fullSupport: true,
20 scannerSupport: true,
21 missingFeatures: []
22 };
23 };
24
25 error = await t.throwsAsync(ScanditSDK.configure(<string>(<unknown>null)));
26 t.is(error.name, "NoLicenseKeyError");
27 error = await t.throwsAsync(ScanditSDK.configure(""));
28 t.is(error.name, "NoLicenseKeyError");
29 error = await t.throwsAsync(ScanditSDK.configure(" "));
30 t.is(error.name, "NoLicenseKeyError");
31 error = await t.throwsAsync(ScanditSDK.configure("YOUR_LICENSE_KEY_IS_NEEDED_HERE"));
32 t.is(error.name, "NoLicenseKeyError");
33 const fakeLicenseKey: string = "#".repeat(64);
34 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey));
35 t.is(ScanditSDK.userLicenseKey, fakeLicenseKey);
36 t.is(ScanditSDK.scanditEngineLocation, baseUrl);
37 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "" }));
38 t.is(ScanditSDK.scanditEngineLocation, baseUrl);
39 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "/" }));
40 t.is(ScanditSDK.scanditEngineLocation, baseUrl);
41 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "test" }));
42 t.is(ScanditSDK.scanditEngineLocation, `${baseUrl}test/`);
43 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "https://example1.com" }));
44 t.is(ScanditSDK.scanditEngineLocation, "https://example1.com/");
45 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "https://example2.com/" }));
46 t.is(ScanditSDK.scanditEngineLocation, "https://example2.com/");
47 Object.defineProperty(window, "location", {
48 value: {
49 href: `${baseDirectory}example.html`,
50 origin: "null"
51 }
52 });
53 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "" }));
54 t.is(ScanditSDK.scanditEngineLocation, baseDirectory);
55 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "/" }));
56 t.is(ScanditSDK.scanditEngineLocation, baseDirectory);
57 await t.notThrowsAsync(ScanditSDK.configure(fakeLicenseKey, { engineLocation: "test" }));
58 t.is(ScanditSDK.scanditEngineLocation, `${baseDirectory}test/`);
59});