@unchainedshop/core-currencies 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ This directory and the files immediately inside it are automatically generated
2
+ when you change this package's NPM dependencies. Commit the files in this
3
+ directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
4
+ so that others run the same versions of sub-dependencies.
5
+
6
+ You should NOT check in the node_modules directory that Meteor automatically
7
+ creates; if you are using git, the .gitignore file tells git to ignore it.
@@ -0,0 +1,40 @@
1
+ {
2
+ "lockfileVersion": 1,
3
+ "dependencies": {
4
+ "clone": {
5
+ "version": "2.1.2",
6
+ "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
7
+ "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w=="
8
+ },
9
+ "lodash._reinterpolate": {
10
+ "version": "3.0.0",
11
+ "resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz",
12
+ "integrity": "sha512-xYHt68QRoYGjeeM/XOE1uJtvXQAgvszfBhjV4yvsQH0u2i9I6cI6c6/eG4Hh3UAOVn0y/xAXwmTzEay49Q//HA=="
13
+ },
14
+ "lodash.template": {
15
+ "version": "4.5.0",
16
+ "resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz",
17
+ "integrity": "sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A=="
18
+ },
19
+ "lodash.templatesettings": {
20
+ "version": "4.2.0",
21
+ "resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz",
22
+ "integrity": "sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ=="
23
+ },
24
+ "message-box": {
25
+ "version": "0.2.7",
26
+ "resolved": "https://registry.npmjs.org/message-box/-/message-box-0.2.7.tgz",
27
+ "integrity": "sha512-C4ccA5nHb58kTS+pLrgF/JWtr7fAIkHxRDceH7tdy5fMA783nUfbYwZ7H2XLvSeYfcnWIYCig5dWW+icK9X/Ag=="
28
+ },
29
+ "mongo-object": {
30
+ "version": "0.1.4",
31
+ "resolved": "https://registry.npmjs.org/mongo-object/-/mongo-object-0.1.4.tgz",
32
+ "integrity": "sha512-QtYk0gupWEn2+iB+DDRt1L+WbcNYvJRaHdih/dcqthOa1DbnREUGSs2WGcW478GNYpElflo/yybZXu0sTiRXHg=="
33
+ },
34
+ "simpl-schema": {
35
+ "version": "1.12.0",
36
+ "resolved": "https://registry.npmjs.org/simpl-schema/-/simpl-schema-1.12.0.tgz",
37
+ "integrity": "sha512-lzXC3L8jJbPhNXGR3cjlyIauqqrC5WUJS4O34Ym/wLIvb8K3ZieK+1OfTzs4mBpDc3Y8u53gQFAr1X37DmTcEg=="
38
+ }
39
+ }
40
+ }
package/.versions ADDED
@@ -0,0 +1,54 @@
1
+ allow-deny@1.1.1
2
+ babel-compiler@7.9.0
3
+ babel-runtime@1.5.1
4
+ base64@1.0.12
5
+ binary-heap@1.0.11
6
+ boilerplate-generator@1.7.1
7
+ callback-hook@1.4.0
8
+ check@1.3.1
9
+ ddp@1.4.0
10
+ ddp-client@2.5.0
11
+ ddp-common@1.4.0
12
+ ddp-server@2.5.0
13
+ diff-sequence@1.1.1
14
+ dynamic-import@0.7.2
15
+ ecmascript@0.16.2
16
+ ecmascript-runtime@0.8.0
17
+ ecmascript-runtime-client@0.12.1
18
+ ecmascript-runtime-server@0.11.0
19
+ ejson@1.1.2
20
+ fetch@0.1.1
21
+ geojson-utils@1.0.10
22
+ id-map@1.1.1
23
+ inter-process-messaging@0.1.1
24
+ local-test:unchained:core-currencies@1.1.1
25
+ logging@1.3.1
26
+ meteor@1.10.0
27
+ meteortesting:browser-tests@0.1.2
28
+ meteortesting:mocha@0.4.4
29
+ minimongo@1.8.0
30
+ modern-browsers@0.1.8
31
+ modules@0.18.0
32
+ modules-runtime@0.13.0
33
+ mongo@1.15.0
34
+ mongo-decimal@0.1.3
35
+ mongo-dev-server@1.1.0
36
+ mongo-id@1.0.8
37
+ npm-mongo@4.3.1
38
+ ordered-dict@1.1.0
39
+ practicalmeteor:mocha-core@1.0.1
40
+ promise@0.12.0
41
+ random@1.2.0
42
+ react-fast-refresh@0.2.3
43
+ reload@1.3.1
44
+ retry@1.1.0
45
+ routepolicy@1.1.1
46
+ socket-stream-client@0.5.0
47
+ tracker@1.2.0
48
+ typescript@4.5.4
49
+ unchained:core-currencies@1.1.1
50
+
51
+ unchained:mongodb@1.1.0
52
+ underscore@1.0.10
53
+ webapp@1.13.1
54
+ webapp-hashing@1.1.0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Currencies (Unchained Engine)
2
+
3
+ This package contains business logic and database abstraction for currencies in Unchained.
@@ -0,0 +1 @@
1
+ export { configureCurrenciesModule } from './module/configureCurrenciesModule';
@@ -0,0 +1,2 @@
1
+ export { configureCurrenciesModule } from './module/configureCurrenciesModule';
2
+ //# sourceMappingURL=currencies-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currencies-index.js","sourceRoot":"","sources":["../src/currencies-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Db } from '@unchainedshop/types/common';
2
+ import { Currency } from '@unchainedshop/types/currencies';
3
+ export declare const CurrenciesCollection: (db: Db) => Promise<import("mongodb").Collection<Currency>>;
@@ -0,0 +1,19 @@
1
+ import { buildDbIndexes } from '@unchainedshop/utils';
2
+ export const CurrenciesCollection = async (db) => {
3
+ const Currencies = db.collection('currencies');
4
+ await buildDbIndexes(Currencies, [
5
+ { index: { isoCode: 1 }, options: { unique: true } },
6
+ {
7
+ index: { isoCode: 'text', _id: 'text' },
8
+ options: {
9
+ weights: {
10
+ _id: 8,
11
+ isoCode: 6,
12
+ },
13
+ name: 'currencies_fulltext_search',
14
+ },
15
+ },
16
+ ]);
17
+ return Currencies;
18
+ };
19
+ //# sourceMappingURL=CurrenciesCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrenciesCollection.js","sourceRoot":"","sources":["../../src/db/CurrenciesCollection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,EAAM,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAW,YAAY,CAAC,CAAC;IAEzD,MAAM,cAAc,CAAW,UAAU,EAAE;QACzC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QACpD;YACE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;YACvC,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,GAAG,EAAE,CAAC;oBACN,OAAO,EAAE,CAAC;iBACX;gBACD,IAAI,EAAE,4BAA4B;aACnC;SACF;KACF,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export const CurrenciesSchema: any;
@@ -0,0 +1,10 @@
1
+ import { Schemas } from '@unchainedshop/utils';
2
+ import SimpleSchema from 'simpl-schema';
3
+ export const CurrenciesSchema = new SimpleSchema({
4
+ isoCode: { type: String, required: true },
5
+ isActive: Boolean,
6
+ authorId: { type: String, required: true },
7
+ contractAddress: { type: String, required: false },
8
+ ...Schemas.timestampFields,
9
+ }, { requiredByDefault: false });
10
+ //# sourceMappingURL=CurrenciesSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrenciesSchema.js","sourceRoot":"","sources":["../../src/db/CurrenciesSchema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,YAAY,CAC9C;IACE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACzC,QAAQ,EAAE,OAAO;IACjB,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC1C,eAAe,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAClD,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ModuleInput } from '@unchainedshop/types/common';
2
+ import { CurrenciesModule } from '@unchainedshop/types/currencies';
3
+ export declare const configureCurrenciesModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<CurrenciesModule>;
@@ -0,0 +1,65 @@
1
+ import { emit, registerEvents } from '@unchainedshop/events';
2
+ import { generateDbMutations, generateDbFilterById, buildSortOptions } from '@unchainedshop/utils';
3
+ import { CurrenciesCollection } from '../db/CurrenciesCollection';
4
+ import { CurrenciesSchema } from '../db/CurrenciesSchema';
5
+ const CURRENCY_EVENTS = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
6
+ const buildFindSelector = ({ includeInactive = false, contractAddress, queryString }) => {
7
+ const selector = {
8
+ deleted: null,
9
+ };
10
+ if (!includeInactive)
11
+ selector.isActive = true;
12
+ if (contractAddress)
13
+ selector.contractAddress = contractAddress;
14
+ if (queryString)
15
+ selector.$text = { $search: queryString };
16
+ return selector;
17
+ };
18
+ export const configureCurrenciesModule = async ({ db, }) => {
19
+ registerEvents(CURRENCY_EVENTS);
20
+ const Currencies = await CurrenciesCollection(db);
21
+ const mutations = generateDbMutations(Currencies, CurrenciesSchema);
22
+ return {
23
+ findCurrency: async ({ currencyId, isoCode }) => {
24
+ return Currencies.findOne(currencyId ? generateDbFilterById(currencyId) : { isoCode });
25
+ },
26
+ findCurrencies: async ({ limit, offset, sort, ...query }) => {
27
+ const currencies = Currencies.find(buildFindSelector(query), {
28
+ skip: offset,
29
+ limit,
30
+ sort: buildSortOptions(sort),
31
+ });
32
+ return currencies.toArray();
33
+ },
34
+ count: async (query) => {
35
+ const count = await Currencies.countDocuments(buildFindSelector(query));
36
+ return count;
37
+ },
38
+ currencyExists: async ({ currencyId }) => {
39
+ const currencyCount = await Currencies.countDocuments(generateDbFilterById(currencyId, { deleted: null }), {
40
+ limit: 1,
41
+ });
42
+ return !!currencyCount;
43
+ },
44
+ create: async (doc, userId) => {
45
+ await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
46
+ const currencyId = await mutations.create({ ...doc, isoCode: doc.isoCode.toUpperCase(), isActive: true }, userId);
47
+ emit('CURRENCY_CREATE', { currencyId });
48
+ return currencyId;
49
+ },
50
+ update: async (_id, doc, userId) => {
51
+ const currencyId = await mutations.update(_id, {
52
+ ...doc,
53
+ isoCode: doc.isoCode.toUpperCase(),
54
+ }, userId);
55
+ emit('CURRENCY_UPDATE', { currencyId });
56
+ return currencyId;
57
+ },
58
+ delete: async (currencyId, userId) => {
59
+ const deletedCount = await mutations.delete(currencyId, userId);
60
+ emit('CURRENCY_REMOVE', { currencyId });
61
+ return deletedCount;
62
+ },
63
+ };
64
+ };
65
+ //# sourceMappingURL=configureCurrenciesModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configureCurrenciesModule.js","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D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AE,KAAK,EAAE,GAAW,EAAE,GAAsB,EAAE,MAAc,EAAE,EAAE;YACpE,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,MAAM,CACvC,GAAG,EACH;gBACE,GAAG,GAAG;gBACN,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE;aACnC,EACD,MAAM,CACP,CAAC;YACF,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YACxC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YACxC,OAAO,YAAY,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.js ADDED
@@ -0,0 +1,32 @@
1
+ Package.describe({
2
+ name: 'unchained:core-currencies',
3
+ version: '1.1.3',
4
+ summary: 'Unchained Engine Core: Currencies',
5
+ git: 'https://github.com/unchainedshop/unchained',
6
+ documentation: 'README.md',
7
+ });
8
+
9
+ Npm.depends({
10
+ 'simpl-schema': '1.12.0',
11
+ '@unchainedshop/utils': '1.1.3',
12
+ // '@unchainedshop/events': '1.1.4', // PEER
13
+ });
14
+
15
+ Package.onUse((api) => {
16
+ api.versionsFrom('2.7.3');
17
+ api.use('ecmascript');
18
+ api.use('typescript');
19
+
20
+ api.mainModule('src/currencies-index.ts', 'server');
21
+ });
22
+
23
+ Package.onTest((api) => {
24
+ api.use('meteortesting:mocha');
25
+ api.use('ecmascript');
26
+ api.use('typescript');
27
+
28
+ api.use('unchained:mongodb@1.1.3');
29
+ api.use('unchained:core-currencies');
30
+
31
+ api.mainModule('tests/currencies-index.test.ts');
32
+ });
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@unchainedshop/core-currencies",
3
+ "version": "1.1.3",
4
+ "main": "lib/currencies-index.js",
5
+ "types": "lib/currencies-index.d.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "clean": "rm -rf lib",
9
+ "build": "npm run clean && tsc -p tsconfig.build.json",
10
+ "watch": "tsc --watch",
11
+ "link:core": "npm link @unchainedshop/types",
12
+ "test": "cross-env METEOR_PACKAGE_DIRS=../ TEST_CLIENT=0 TEST_WATCH=1 meteor test-packages ./ --driver-package meteortesting:mocha --port 4200"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/unchainedshop/unchained.git"
17
+ },
18
+ "keywords": [
19
+ "unchained",
20
+ "ecommerce",
21
+ "core"
22
+ ],
23
+ "author": "Joël Meiller",
24
+ "license": "EUPL-1.2",
25
+ "bugs": {
26
+ "url": "https://github.com/unchainedshop/unchained/issues"
27
+ },
28
+ "homepage": "https://github.com/unchainedshop/unchained#readme",
29
+ "dependencies": {
30
+ "@unchainedshop/events": "latest",
31
+ "@unchainedshop/utils": "latest",
32
+ "simpl-schema": "^1.12.2"
33
+ },
34
+ "devDependencies": {
35
+ "@types/chai": "^4.3.1",
36
+ "@types/mocha": "^9.1.1",
37
+ "@unchainedshop/types": "latest",
38
+ "chai": "^4.3.6",
39
+ "cross-env": "^7.0.3",
40
+ "typescript": "^4.7.4"
41
+ }
42
+ }
@@ -0,0 +1 @@
1
+ export { configureCurrenciesModule } from './module/configureCurrenciesModule';
@@ -0,0 +1,23 @@
1
+ import { Db } from '@unchainedshop/types/common';
2
+ import { Currency } from '@unchainedshop/types/currencies';
3
+ import { buildDbIndexes } from '@unchainedshop/utils';
4
+
5
+ export const CurrenciesCollection = async (db: Db) => {
6
+ const Currencies = db.collection<Currency>('currencies');
7
+
8
+ await buildDbIndexes<Currency>(Currencies, [
9
+ { index: { isoCode: 1 }, options: { unique: true } },
10
+ {
11
+ index: { isoCode: 'text', _id: 'text' },
12
+ options: {
13
+ weights: {
14
+ _id: 8,
15
+ isoCode: 6,
16
+ },
17
+ name: 'currencies_fulltext_search',
18
+ },
19
+ },
20
+ ]);
21
+
22
+ return Currencies;
23
+ };
@@ -0,0 +1,13 @@
1
+ import { Schemas } from '@unchainedshop/utils';
2
+ import SimpleSchema from 'simpl-schema';
3
+
4
+ export const CurrenciesSchema = new SimpleSchema(
5
+ {
6
+ isoCode: { type: String, required: true },
7
+ isActive: Boolean,
8
+ authorId: { type: String, required: true },
9
+ contractAddress: { type: String, required: false },
10
+ ...Schemas.timestampFields,
11
+ },
12
+ { requiredByDefault: false },
13
+ );
@@ -0,0 +1,88 @@
1
+ import { ModuleInput, ModuleMutations } from '@unchainedshop/types/common';
2
+ import { CurrenciesModule, Currency, CurrencyQuery } from '@unchainedshop/types/currencies';
3
+ import { emit, registerEvents } from '@unchainedshop/events';
4
+ import { generateDbMutations, generateDbFilterById, buildSortOptions } from '@unchainedshop/utils';
5
+ import { CurrenciesCollection } from '../db/CurrenciesCollection';
6
+ import { CurrenciesSchema } from '../db/CurrenciesSchema';
7
+
8
+ const CURRENCY_EVENTS: string[] = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
9
+
10
+ const buildFindSelector = ({ includeInactive = false, contractAddress, queryString }: CurrencyQuery) => {
11
+ const selector: { isActive?: true; deleted: null; contractAddress?: string; $text?: any } = {
12
+ deleted: null,
13
+ };
14
+ if (!includeInactive) selector.isActive = true;
15
+ if (contractAddress) selector.contractAddress = contractAddress;
16
+ if (queryString) selector.$text = { $search: queryString };
17
+ return selector;
18
+ };
19
+
20
+ export const configureCurrenciesModule = async ({
21
+ db,
22
+ }: ModuleInput<Record<string, never>>): Promise<CurrenciesModule> => {
23
+ registerEvents(CURRENCY_EVENTS);
24
+
25
+ const Currencies = await CurrenciesCollection(db);
26
+
27
+ const mutations = generateDbMutations<Currency>(
28
+ Currencies,
29
+ CurrenciesSchema,
30
+ ) as ModuleMutations<Currency>;
31
+
32
+ return {
33
+ findCurrency: async ({ currencyId, isoCode }) => {
34
+ return Currencies.findOne(currencyId ? generateDbFilterById(currencyId) : { isoCode });
35
+ },
36
+
37
+ findCurrencies: async ({ limit, offset, sort, ...query }) => {
38
+ const currencies = Currencies.find(buildFindSelector(query), {
39
+ skip: offset,
40
+ limit,
41
+ sort: buildSortOptions(sort),
42
+ });
43
+ return currencies.toArray();
44
+ },
45
+
46
+ count: async (query) => {
47
+ const count = await Currencies.countDocuments(buildFindSelector(query));
48
+ return count;
49
+ },
50
+
51
+ currencyExists: async ({ currencyId }) => {
52
+ const currencyCount = await Currencies.countDocuments(
53
+ generateDbFilterById(currencyId, { deleted: null }),
54
+ {
55
+ limit: 1,
56
+ },
57
+ );
58
+ return !!currencyCount;
59
+ },
60
+
61
+ create: async (doc: Currency, userId: string) => {
62
+ await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
63
+ const currencyId = await mutations.create(
64
+ { ...doc, isoCode: doc.isoCode.toUpperCase(), isActive: true },
65
+ userId,
66
+ );
67
+ emit('CURRENCY_CREATE', { currencyId });
68
+ return currencyId;
69
+ },
70
+ update: async (_id: string, doc: Partial<Currency>, userId: string) => {
71
+ const currencyId = await mutations.update(
72
+ _id,
73
+ {
74
+ ...doc,
75
+ isoCode: doc.isoCode.toUpperCase(),
76
+ },
77
+ userId,
78
+ );
79
+ emit('CURRENCY_UPDATE', { currencyId });
80
+ return currencyId;
81
+ },
82
+ delete: async (currencyId, userId) => {
83
+ const deletedCount = await mutations.delete(currencyId, userId);
84
+ emit('CURRENCY_REMOVE', { currencyId });
85
+ return deletedCount;
86
+ },
87
+ };
88
+ };
@@ -0,0 +1,47 @@
1
+ import { assert } from 'chai';
2
+ import { initDb } from 'meteor/unchained:mongodb';
3
+ import { configureCurrenciesModule } from 'meteor/unchained:core-currencies';
4
+
5
+ describe('Test exports', () => {
6
+ let module;
7
+
8
+ before(async () => {
9
+ const db = await initDb();
10
+ module = await configureCurrenciesModule({ db });
11
+ });
12
+
13
+ it('Check Bookmarks module', async () => {
14
+ assert.ok(module);
15
+ assert.isFunction(module.findCurrency);
16
+ assert.isFunction(module.findCurrencies);
17
+ assert.isFunction(module.currencyExists);
18
+ assert.isFunction(module.create);
19
+ assert.isFunction(module.update);
20
+ assert.isFunction(module.delete);
21
+ });
22
+
23
+ it('Mutate currency', async () => {
24
+ const currencyId = await module.create(
25
+ {
26
+ authorId: 'Test-User-1',
27
+ isoCode: 'CHF',
28
+ },
29
+ 'Test-User-1'
30
+ );
31
+
32
+ assert.ok(currencyId);
33
+ const currency = await module.findCurrency(currencyId);
34
+
35
+ assert.ok(currency);
36
+ assert.equal(currency._id, currencyId);
37
+ assert.equal(currency.isoCode, 'CHF');
38
+ assert.equal(currency.userId, 'Test-User-1');
39
+ assert.isDefined(currency.created);
40
+ assert.isUndefined(currency.updated);
41
+ assert.isUndefined(currency.updatedBy);
42
+ assert.equal(currency.createdBy, 'Test-User-1');
43
+
44
+ const deletedCount = await module.delete(currencyId);
45
+ assert.equal(deletedCount, 1);
46
+ });
47
+ });
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "allowSyntheticDefaultImports": true,
5
+ "declaration": true,
6
+ "esModuleInterop": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "lib": ["esnext"],
10
+ "module": "esnext",
11
+ "moduleResolution": "node",
12
+ "noImplicitReturns": true,
13
+ "noUnusedLocals": false,
14
+ "outDir": "lib",
15
+ "preserveWatchOutput": true,
16
+ "skipLibCheck": true,
17
+ "sourceMap": true,
18
+ "target": "esnext",
19
+ "types": ["node"],
20
+ "baseUrl": ".", // This must be specified if "paths" is.
21
+ "paths": {
22
+ "meteor/unchained:*": ["node_modules/@unchainedshop/types/index.d.ts"]
23
+ }
24
+ },
25
+ "include": ["src"]
26
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "types": ["node", "mocha"]
6
+ },
7
+ "include": ["src", "tests"]
8
+ }