@webresto/graphql 1.3.7 → 1.3.8
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.
- package/.gitattributes +2 -0
- package/.gitlab-ci.yml +18 -0
- package/.vscode/extensions.json +5 -0
- package/docs/actions.md +25 -0
- package/docs/authorization.md +215 -0
- package/docs/captcha.md +71 -0
- package/docs/device-id.md +30 -0
- package/docs/messages.md +10 -0
- package/docs/user.md +54 -0
- package/index.d.ts +0 -1
- package/index.js +6 -2
- package/index.ts +2 -2
- package/lib/afterHook.js +8 -0
- package/lib/afterHook.ts +9 -0
- package/lib/bindTranslations.d.ts +1 -0
- package/lib/bindTranslations.js +40 -0
- package/lib/bindTranslations.ts +39 -0
- package/lib/defaults.d.ts +1 -0
- package/lib/defaults.js +49 -10
- package/lib/defaults.ts +55 -0
- package/lib/eventHelper.d.ts +14 -5
- package/lib/eventHelper.js +28 -9
- package/lib/eventHelper.ts +41 -8
- package/lib/getRecomended.d.ts +1 -0
- package/lib/getRecomended.js +29 -0
- package/lib/getRecomended.ts +31 -0
- package/lib/graphqlHelper.d.ts +3 -4
- package/lib/graphqlHelper.js +184 -72
- package/lib/graphqlHelper.ts +329 -185
- package/lib/jwt.d.ts +10 -0
- package/lib/jwt.js +43 -0
- package/lib/jwt.ts +61 -0
- package/package.json +13 -6
- package/src/additionalResolvers.d.ts +72 -9
- package/src/additionalResolvers.js +93 -24
- package/src/additionalResolvers.ts +105 -34
- package/src/graphql.d.ts +5 -3
- package/src/graphql.js +170 -37
- package/src/graphql.ts +210 -60
- package/src/resolvers/bonusProgram.d.ts +32 -0
- package/src/resolvers/bonusProgram.js +65 -0
- package/src/resolvers/bonusProgram.ts +79 -0
- package/src/resolvers/captcha.d.ts +11 -0
- package/src/resolvers/captcha.js +19 -0
- package/src/resolvers/captcha.ts +16 -0
- package/src/resolvers/checkout.d.ts +35 -16
- package/src/resolvers/checkout.js +171 -94
- package/src/resolvers/checkout.ts +214 -104
- package/src/resolvers/dishAndModifier.js +8 -4
- package/src/resolvers/dishAndModifier.ts +4 -0
- package/src/resolvers/error.d.ts +9 -0
- package/src/resolvers/error.js +21 -0
- package/src/resolvers/error.ts +21 -0
- package/src/resolvers/menu.d.ts +9 -0
- package/src/resolvers/menu.js +12 -0
- package/src/resolvers/menu.ts +10 -0
- package/src/resolvers/order.d.ts +527 -0
- package/src/resolvers/order.js +349 -0
- package/src/resolvers/order.ts +435 -0
- package/src/resolvers/paymentMethod.js +7 -3
- package/src/resolvers/paymentMethod.ts +9 -5
- package/src/resolvers/pickupPoint.d.ts +1 -0
- package/src/resolvers/pickupPoint.js +24 -0
- package/src/resolvers/pickupPoint.ts +23 -0
- package/src/resolvers/recomended.d.ts +13 -0
- package/src/resolvers/recomended.js +80 -0
- package/src/resolvers/recomended.ts +86 -0
- package/src/resolvers/restrictions.d.ts +37 -1
- package/src/resolvers/restrictions.js +100 -15
- package/src/resolvers/restrictions.ts +106 -14
- package/src/resolvers/streets.d.ts +1 -1
- package/src/resolvers/streets.js +1 -4
- package/src/resolvers/streets.ts +1 -3
- package/src/resolvers/subscriptions.d.ts +4 -4
- package/src/resolvers/subscriptions.js +49 -12
- package/src/resolvers/subscriptions.ts +59 -14
- package/src/resolvers/telemetry.d.ts +14 -0
- package/src/resolvers/telemetry.js +25 -0
- package/src/resolvers/telemetry.ts +24 -0
- package/src/resolvers/user.d.ts +82 -0
- package/src/resolvers/user.js +416 -0
- package/src/resolvers/user.ts +621 -0
- package/src/resolvers/userLocation.d.ts +53 -0
- package/src/resolvers/userLocation.js +74 -0
- package/src/resolvers/userLocation.ts +125 -0
- package/src/resolvers/userOTPrequest.d.ts +21 -0
- package/src/resolvers/userOTPrequest.js +57 -0
- package/src/resolvers/userOTPrequest.ts +75 -0
- package/test/e2e_helper.js +157 -0
- package/test/e2e_helper.ts +212 -0
- package/test/fixture/config/i18n.js +7 -20
- package/test/fixture/config/locales/de.json +1 -0
- package/test/fixture/config/locales/en.json +10 -0
- package/test/fixture/config/locales/es.json +3 -0
- package/test/fixture/config/locales/fr.json +1 -0
- package/test/fixture/config/log.js +1 -1
- package/test/fixture/package.json +5 -6
- package/test/fixture/patches/rttc+10.0.1.patch +17 -0
- package/test/integration/captcha.test.js +20 -0
- package/test/integration/captcha.test.ts +25 -0
- package/test/integration/dish.test.js +35 -0
- package/test/integration/dish.test.ts +43 -0
- package/test/integration/graphql.test.js +5 -2
- package/test/integration/graphql.test.ts +2 -4
- package/test/integration/images.test.js +35 -0
- package/test/integration/images.test.ts +40 -0
- package/test/integration/locale.test.js +26 -0
- package/test/integration/locale.test.ts +32 -0
- package/test/integration/order.test.js +56 -43
- package/test/integration/order.test.ts +59 -59
- package/test/integration/subscriptions.test.js +136 -0
- package/test/integration/subscriptions.test.ts +162 -0
- package/test/integration/user.test.js +249 -0
- package/test/integration/user.test.ts +299 -0
- package/test/unit/first.test.js +4 -2
- package/test/unit/first.test.ts +1 -1
- package/test/unit/get-recomended.test.js +56 -0
- package/test/unit/get-recomended.test.ts +63 -0
- package/translations/de.json +2 -0
- package/translations/en.json +3 -0
- package/translations/es.json +3 -0
- package/translations/fr.json +2 -0
- package/translations/ru.json +36 -0
- package/tsconfig.json +20 -5
- package/types/global.d.ts +30 -0
- package/types/global.js +2 -0
- package/types/global.ts +31 -0
- package/types/primitives.d.ts +19 -0
- package/types/references.d.ts +1 -0
- package/types/restoGraphQLConfig.d.ts +13 -0
- package/lib/afterHook.ts___graphql-transport-ws +0 -138
- package/lib/afterHook.ts___graphql-ws +0 -133
- package/lib/errorWrapper.d.ts +0 -4
- package/lib/errorWrapper.js +0 -13
- package/lib/errorWrapper.ts +0 -12
- package/notes.md +0 -1976
- package/src/resolvers/cart.d.ts +0 -343
- package/src/resolvers/cart.js +0 -196
- package/src/resolvers/cart.ts +0 -278
- package/test/fixture/config/connections.js +0 -9
- package/test/integration/sails_not_crash.test.js +0 -3
- package/test/integration/sails_not_crash.test.ts +0 -3
|
@@ -1,43 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const e2e_helper_1 = require("../e2e_helper");
|
|
5
|
+
describe('Check send order', function () {
|
|
6
|
+
let headers = {
|
|
7
|
+
'x-device-id': '123testDeviceId',
|
|
8
|
+
};
|
|
3
9
|
it('Create new', async () => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
expect(result.errors).to.be.undefined;
|
|
10
|
+
const query = `#graphql
|
|
11
|
+
{order(orderId:"test-cart"){
|
|
12
|
+
id
|
|
13
|
+
total
|
|
14
|
+
}}`;
|
|
15
|
+
const result = await (0, e2e_helper_1.runGQL)(query, headers);
|
|
16
|
+
(0, chai_1.expect)(result.errors).to.be.undefined;
|
|
13
17
|
});
|
|
14
18
|
it('orderAddDish', async () => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
name
|
|
23
|
-
price
|
|
24
|
-
}
|
|
25
|
-
itemTotal
|
|
19
|
+
const query = `#graphql
|
|
20
|
+
mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
|
|
21
|
+
dishes {
|
|
22
|
+
dish {
|
|
23
|
+
id
|
|
24
|
+
name
|
|
25
|
+
price
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
itemTotal
|
|
28
|
+
}
|
|
29
|
+
total
|
|
30
|
+
}}
|
|
31
|
+
`;
|
|
32
|
+
const result = await (0, e2e_helper_1.runGQL)(query, headers);
|
|
33
|
+
(0, chai_1.expect)(result.data.orderAddDish.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
|
32
34
|
});
|
|
33
35
|
it('checkOrder', async () => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
const query = `#graphql
|
|
37
|
+
mutation{checkOrder(orderCheckout: {
|
|
38
|
+
orderId: "test-cart",
|
|
39
|
+
paymentMethodId: "",
|
|
40
|
+
address: {
|
|
41
|
+
city: "town",
|
|
42
|
+
street: "test",
|
|
43
|
+
home: "123"
|
|
44
|
+
},
|
|
45
|
+
customer: {
|
|
46
|
+
phone: {
|
|
47
|
+
code: "+1",
|
|
48
|
+
number: "0000000000"
|
|
49
|
+
},
|
|
50
|
+
name: "Piter Parker"
|
|
51
|
+
}
|
|
52
|
+
}) {
|
|
53
|
+
order {
|
|
54
|
+
id
|
|
55
|
+
state
|
|
41
56
|
dishes{
|
|
42
57
|
dish {
|
|
43
58
|
name
|
|
@@ -50,14 +65,12 @@ describe('Send order to restarant', function () {
|
|
|
50
65
|
message
|
|
51
66
|
}
|
|
52
67
|
}}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
expect(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
|
68
|
+
`;
|
|
69
|
+
const result = await (0, e2e_helper_1.runGQL)(query, headers);
|
|
70
|
+
(0, chai_1.expect)(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
|
56
71
|
});
|
|
57
72
|
it('sendOrder', async () => {
|
|
58
|
-
const
|
|
59
|
-
const result = await graphql.getServer().executeOperation({
|
|
60
|
-
query: `
|
|
73
|
+
const query = `
|
|
61
74
|
mutation{sendOrder(orderId:"test-cart") {
|
|
62
75
|
order {
|
|
63
76
|
id
|
|
@@ -75,8 +88,8 @@ describe('Send order to restarant', function () {
|
|
|
75
88
|
message
|
|
76
89
|
}
|
|
77
90
|
}}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
expect(result.data.sendOrder.order.state).to.equal("ORDER");
|
|
91
|
+
`;
|
|
92
|
+
const result = await (0, e2e_helper_1.runGQL)(query, headers);
|
|
93
|
+
(0, chai_1.expect)(result.data.sendOrder.order.state).to.equal("ORDER");
|
|
81
94
|
});
|
|
82
95
|
});
|
|
@@ -1,56 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
import {expect} from "chai"
|
|
2
|
+
import { runGQL } from "../e2e_helper";
|
|
2
3
|
|
|
3
|
-
describe('
|
|
4
|
-
it('Create new', async () => {
|
|
5
|
-
|
|
6
|
-
const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
|
|
7
|
-
const result = await graphql.getServer().executeOperation({
|
|
8
|
-
query: `
|
|
9
|
-
{order(orderId:"test-cart"){
|
|
10
|
-
id
|
|
11
|
-
total
|
|
12
|
-
}}`
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
expect(result.errors).to.be.undefined;
|
|
16
|
-
});
|
|
4
|
+
describe('Check send order', function () {
|
|
17
5
|
|
|
6
|
+
let headers = {
|
|
7
|
+
'x-device-id': '123testDeviceId',
|
|
8
|
+
}
|
|
18
9
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
it('Create new', async () => {
|
|
11
|
+
const query = `#graphql
|
|
12
|
+
{order(orderId:"test-cart"){
|
|
13
|
+
id
|
|
14
|
+
total
|
|
15
|
+
}}`;
|
|
16
|
+
|
|
17
|
+
const result = await runGQL(query, headers);
|
|
18
|
+
expect(result.errors).to.be.undefined;
|
|
19
|
+
});
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
name
|
|
32
|
-
price
|
|
33
|
-
}
|
|
34
|
-
itemTotal
|
|
21
|
+
it('orderAddDish', async () => {
|
|
22
|
+
const query = `#graphql
|
|
23
|
+
mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
|
|
24
|
+
dishes {
|
|
25
|
+
dish {
|
|
26
|
+
id
|
|
27
|
+
name
|
|
28
|
+
price
|
|
35
29
|
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
itemTotal
|
|
31
|
+
}
|
|
32
|
+
total
|
|
33
|
+
}}
|
|
34
|
+
`;
|
|
35
|
+
const result = await runGQL(query, headers);
|
|
40
36
|
expect(result.data.orderAddDish.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
|
41
37
|
});
|
|
42
38
|
|
|
43
39
|
|
|
44
40
|
it('checkOrder', async () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
const query = `#graphql
|
|
42
|
+
mutation{checkOrder(orderCheckout: {
|
|
43
|
+
orderId: "test-cart",
|
|
44
|
+
paymentMethodId: "",
|
|
45
|
+
address: {
|
|
46
|
+
city: "town",
|
|
47
|
+
street: "test",
|
|
48
|
+
home: "123"
|
|
49
|
+
},
|
|
50
|
+
customer: {
|
|
51
|
+
phone: {
|
|
52
|
+
code: "+1",
|
|
53
|
+
number: "0000000000"
|
|
54
|
+
},
|
|
55
|
+
name: "Piter Parker"
|
|
56
|
+
}
|
|
57
|
+
}) {
|
|
58
|
+
order {
|
|
59
|
+
id
|
|
60
|
+
state
|
|
54
61
|
dishes{
|
|
55
62
|
dish {
|
|
56
63
|
name
|
|
@@ -63,19 +70,16 @@ describe('Send order to restarant', function () {
|
|
|
63
70
|
message
|
|
64
71
|
}
|
|
65
72
|
}}
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
expect(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
|
69
|
-
});
|
|
73
|
+
`;
|
|
70
74
|
|
|
75
|
+
const result = await runGQL(query, headers);
|
|
76
|
+
expect(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
|
|
77
|
+
});
|
|
71
78
|
|
|
72
79
|
|
|
73
|
-
it('sendOrder', async () => {
|
|
74
80
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const result = await graphql.getServer().executeOperation({
|
|
78
|
-
query: `
|
|
81
|
+
it('sendOrder', async () => {
|
|
82
|
+
const query = `
|
|
79
83
|
mutation{sendOrder(orderId:"test-cart") {
|
|
80
84
|
order {
|
|
81
85
|
id
|
|
@@ -93,15 +97,11 @@ describe('Send order to restarant', function () {
|
|
|
93
97
|
message
|
|
94
98
|
}
|
|
95
99
|
}}
|
|
96
|
-
|
|
97
|
-
});
|
|
100
|
+
`;
|
|
98
101
|
|
|
102
|
+
const result = await runGQL(query, headers);
|
|
99
103
|
expect(result.data.sendOrder.order.state).to.equal("ORDER");
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
});
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const e2e = require("../e2e_helper");
|
|
5
|
+
const e2e_helper_1 = require("../e2e_helper");
|
|
6
|
+
const apollo_server_core_1 = require("apollo-server-core");
|
|
7
|
+
const e2e_helper_2 = require("../e2e_helper");
|
|
8
|
+
describe("Test subscritions", function () {
|
|
9
|
+
this.timeout(50000);
|
|
10
|
+
let gqlClient;
|
|
11
|
+
let headers = {
|
|
12
|
+
'x-device-id': '123testDeviceId',
|
|
13
|
+
};
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
gqlClient = new e2e_helper_1.TestApolloClient({
|
|
16
|
+
host: "127.0.0.1",
|
|
17
|
+
port: "42772"
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
// afterEach(() => gqlClient.stop())
|
|
21
|
+
it('maintenance', async () => {
|
|
22
|
+
const sub = e2e.createSubscription({
|
|
23
|
+
client: gqlClient,
|
|
24
|
+
query: (0, apollo_server_core_1.gql) `
|
|
25
|
+
subscription {
|
|
26
|
+
maintenance {
|
|
27
|
+
description
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`
|
|
31
|
+
});
|
|
32
|
+
await Maintenance.create({ description: "test", enable: true }).fetch();
|
|
33
|
+
let len = await Maintenance.count();
|
|
34
|
+
await sub.waitForResults();
|
|
35
|
+
(0, chai_1.expect)(sub.results).to.be.of.length(1);
|
|
36
|
+
await Maintenance.destroy({}).fetch();
|
|
37
|
+
await sub.waitForResults({ len: len });
|
|
38
|
+
(0, chai_1.expect)(sub.results).to.be.of.length(len + 1);
|
|
39
|
+
(0, chai_1.expect)(sub.results[1].data.maintenance).to.equal(null);
|
|
40
|
+
sub.disconnect(); // unsubscribe
|
|
41
|
+
});
|
|
42
|
+
it('order', async () => {
|
|
43
|
+
const query = `{order(orderId:"test-subscription-cart"){
|
|
44
|
+
id
|
|
45
|
+
total
|
|
46
|
+
}}`;
|
|
47
|
+
await (0, e2e_helper_2.runGQL)(query, headers);
|
|
48
|
+
const sub = e2e.createSubscription({
|
|
49
|
+
client: gqlClient,
|
|
50
|
+
query: (0, apollo_server_core_1.gql) `
|
|
51
|
+
subscription {
|
|
52
|
+
order(deviceId:"${headers["x-device-id"]}") {
|
|
53
|
+
dishesCount
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`
|
|
57
|
+
});
|
|
58
|
+
const query_orderAddDish = `#graphql
|
|
59
|
+
mutation {
|
|
60
|
+
orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-subscription-cart", amount: 7){
|
|
61
|
+
dishes {
|
|
62
|
+
dish {
|
|
63
|
+
id
|
|
64
|
+
name
|
|
65
|
+
price
|
|
66
|
+
}
|
|
67
|
+
itemTotal
|
|
68
|
+
}
|
|
69
|
+
total
|
|
70
|
+
}
|
|
71
|
+
}`;
|
|
72
|
+
await (0, e2e_helper_2.runGQL)(query_orderAddDish, headers);
|
|
73
|
+
await sub.waitForResults();
|
|
74
|
+
(0, chai_1.expect)(sub.results[0].data.order.dishesCount).to.equal(7);
|
|
75
|
+
sub.disconnect(); // unsubscribe
|
|
76
|
+
});
|
|
77
|
+
it('action', async () => {
|
|
78
|
+
const eventHelper = require("../../lib/eventHelper");
|
|
79
|
+
const sub = e2e.createSubscription({
|
|
80
|
+
client: gqlClient,
|
|
81
|
+
query: (0, apollo_server_core_1.gql) `
|
|
82
|
+
subscription {
|
|
83
|
+
action(deviceId:"${headers["x-device-id"]}") {
|
|
84
|
+
id
|
|
85
|
+
type
|
|
86
|
+
data
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`
|
|
90
|
+
});
|
|
91
|
+
await sub.wait(700);
|
|
92
|
+
const action = {
|
|
93
|
+
deviceId: headers["x-device-id"],
|
|
94
|
+
type: "test",
|
|
95
|
+
data: {
|
|
96
|
+
test: true,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
let event = eventHelper.sendAction(action);
|
|
100
|
+
await sub.waitForResults();
|
|
101
|
+
(0, chai_1.expect)(sub.results).to.be.of.length(1);
|
|
102
|
+
(0, chai_1.expect)(sub.results[0].data.action.id).be.not.null;
|
|
103
|
+
(0, chai_1.expect)(sub.results[0].data.action.data.test).to.equal(true);
|
|
104
|
+
sub.disconnect(); // unsubscribe
|
|
105
|
+
});
|
|
106
|
+
it('message', async () => {
|
|
107
|
+
const eventHelper = require("../../lib/eventHelper");
|
|
108
|
+
const sub = e2e.createSubscription({
|
|
109
|
+
client: gqlClient,
|
|
110
|
+
query: (0, apollo_server_core_1.gql) `
|
|
111
|
+
subscription {
|
|
112
|
+
message(deviceId:"${headers["x-device-id"]}") {
|
|
113
|
+
id
|
|
114
|
+
title
|
|
115
|
+
type
|
|
116
|
+
message
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
`
|
|
120
|
+
});
|
|
121
|
+
await sub.wait(700);
|
|
122
|
+
let message = {
|
|
123
|
+
deviceId: headers["x-device-id"],
|
|
124
|
+
type: "info",
|
|
125
|
+
title: "TEST",
|
|
126
|
+
message: "TEST",
|
|
127
|
+
};
|
|
128
|
+
eventHelper.sendMessage(message);
|
|
129
|
+
await sub.waitForResults();
|
|
130
|
+
(0, chai_1.expect)(sub.results).to.be.of.length(1);
|
|
131
|
+
(0, chai_1.expect)(sub.results[0].data.message.id).be.not.null;
|
|
132
|
+
(0, chai_1.expect)(sub.results[0].data.message.title).to.equal("TEST");
|
|
133
|
+
(0, chai_1.expect)(sub.results[0].data.message.message).to.equal("TEST");
|
|
134
|
+
sub.disconnect(); // unsubscribe
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import * as e2e from '../e2e_helper'
|
|
3
|
+
import { TestApolloClient } from '../e2e_helper';
|
|
4
|
+
import { gql } from "apollo-server-core"
|
|
5
|
+
|
|
6
|
+
import { runGQL } from "../e2e_helper";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
describe("Test subscritions", function () {
|
|
10
|
+
this.timeout(50000)
|
|
11
|
+
let gqlClient : e2e.TestApolloClient;
|
|
12
|
+
|
|
13
|
+
let headers = {
|
|
14
|
+
'x-device-id': '123testDeviceId',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
gqlClient = new TestApolloClient({
|
|
19
|
+
host: "127.0.0.1",
|
|
20
|
+
port: "42772"
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// afterEach(() => gqlClient.stop())
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
it('maintenance', async () => {
|
|
28
|
+
const sub = e2e.createSubscription({
|
|
29
|
+
client: gqlClient,
|
|
30
|
+
query: gql`
|
|
31
|
+
subscription {
|
|
32
|
+
maintenance {
|
|
33
|
+
description
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await Maintenance.create({description: "test", enable: true}).fetch()
|
|
40
|
+
let len = await Maintenance.count()
|
|
41
|
+
await sub.waitForResults();
|
|
42
|
+
expect(sub.results).to.be.of.length(1);
|
|
43
|
+
|
|
44
|
+
await Maintenance.destroy({}).fetch()
|
|
45
|
+
await sub.waitForResults({len:len});
|
|
46
|
+
expect(sub.results).to.be.of.length(len+1);
|
|
47
|
+
expect(sub.results[1].data.maintenance).to.equal(null);
|
|
48
|
+
sub.disconnect(); // unsubscribe
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
it('order', async () => {
|
|
53
|
+
|
|
54
|
+
const query = `{order(orderId:"test-subscription-cart"){
|
|
55
|
+
id
|
|
56
|
+
total
|
|
57
|
+
}}`;
|
|
58
|
+
|
|
59
|
+
await runGQL(query, headers);
|
|
60
|
+
|
|
61
|
+
const sub = e2e.createSubscription({
|
|
62
|
+
client: gqlClient,
|
|
63
|
+
query: gql`
|
|
64
|
+
subscription {
|
|
65
|
+
order(deviceId:"${headers["x-device-id"]}") {
|
|
66
|
+
dishesCount
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const query_orderAddDish = `#graphql
|
|
73
|
+
mutation {
|
|
74
|
+
orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-subscription-cart", amount: 7){
|
|
75
|
+
dishes {
|
|
76
|
+
dish {
|
|
77
|
+
id
|
|
78
|
+
name
|
|
79
|
+
price
|
|
80
|
+
}
|
|
81
|
+
itemTotal
|
|
82
|
+
}
|
|
83
|
+
total
|
|
84
|
+
}
|
|
85
|
+
}`;
|
|
86
|
+
|
|
87
|
+
await runGQL(query_orderAddDish, headers);
|
|
88
|
+
|
|
89
|
+
await sub.waitForResults();
|
|
90
|
+
expect(sub.results[0].data.order.dishesCount).to.equal(7)
|
|
91
|
+
sub.disconnect(); // unsubscribe
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('action', async () => {
|
|
95
|
+
const eventHelper: typeof import("../../lib/eventHelper") = require("../../lib/eventHelper");
|
|
96
|
+
const sub = e2e.createSubscription({
|
|
97
|
+
client: gqlClient,
|
|
98
|
+
query: gql`
|
|
99
|
+
subscription {
|
|
100
|
+
action(deviceId:"${headers["x-device-id"]}") {
|
|
101
|
+
id
|
|
102
|
+
type
|
|
103
|
+
data
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
await sub.wait(700);
|
|
111
|
+
const action = {
|
|
112
|
+
deviceId: headers["x-device-id"],
|
|
113
|
+
type: "test",
|
|
114
|
+
data: {
|
|
115
|
+
test: true,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
let event = eventHelper.sendAction(action);
|
|
120
|
+
await sub.waitForResults();
|
|
121
|
+
expect(sub.results).to.be.of.length(1);
|
|
122
|
+
expect(sub.results[0].data.action.id).be.not.null;
|
|
123
|
+
expect(sub.results[0].data.action.data.test).to.equal(true);
|
|
124
|
+
|
|
125
|
+
sub.disconnect(); // unsubscribe
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('message', async () => {
|
|
129
|
+
const eventHelper: typeof import("../../lib/eventHelper") = require("../../lib/eventHelper");
|
|
130
|
+
const sub = e2e.createSubscription({
|
|
131
|
+
client: gqlClient,
|
|
132
|
+
query: gql`
|
|
133
|
+
subscription {
|
|
134
|
+
message(deviceId:"${headers["x-device-id"]}") {
|
|
135
|
+
id
|
|
136
|
+
title
|
|
137
|
+
type
|
|
138
|
+
message
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
`
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
await sub.wait(700);
|
|
146
|
+
let message = {
|
|
147
|
+
deviceId: headers["x-device-id"],
|
|
148
|
+
type: "info" as "info",
|
|
149
|
+
title: "TEST",
|
|
150
|
+
message: "TEST",
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
eventHelper.sendMessage(message);
|
|
154
|
+
await sub.waitForResults();
|
|
155
|
+
expect(sub.results).to.be.of.length(1);
|
|
156
|
+
expect(sub.results[0].data.message.id).be.not.null;
|
|
157
|
+
expect(sub.results[0].data.message.title).to.equal("TEST");
|
|
158
|
+
expect(sub.results[0].data.message.message).to.equal("TEST");
|
|
159
|
+
|
|
160
|
+
sub.disconnect(); // unsubscribe
|
|
161
|
+
})
|
|
162
|
+
})
|