@snowtop/ent 0.1.0-alpha160-test7 → 0.1.0-alpha160
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/core/query/shared_assoc_test.d.ts +2 -0
- package/core/query/shared_assoc_test.js +804 -0
- package/core/query/shared_test.d.ts +21 -0
- package/core/query/shared_test.js +736 -0
- package/graphql/query/shared_assoc_test.d.ts +1 -0
- package/graphql/query/shared_assoc_test.js +203 -0
- package/package.json +8 -53
- package/dist/package.json +0 -64
- package/src/action/action.ts +0 -330
- package/src/action/executor.ts +0 -453
- package/src/action/experimental_action.ts +0 -277
- package/src/action/index.ts +0 -31
- package/src/action/operations.ts +0 -967
- package/src/action/orchestrator.ts +0 -1527
- package/src/action/privacy.ts +0 -37
- package/src/action/relative_value.ts +0 -242
- package/src/action/transaction.ts +0 -38
- package/src/auth/auth.ts +0 -77
- package/src/auth/index.ts +0 -8
- package/src/core/base.ts +0 -367
- package/src/core/clause.ts +0 -1065
- package/src/core/config.ts +0 -219
- package/src/core/const.ts +0 -5
- package/src/core/context.ts +0 -135
- package/src/core/convert.ts +0 -106
- package/src/core/date.ts +0 -23
- package/src/core/db.ts +0 -498
- package/src/core/ent.ts +0 -1740
- package/src/core/global_schema.ts +0 -49
- package/src/core/loaders/assoc_count_loader.ts +0 -99
- package/src/core/loaders/assoc_edge_loader.ts +0 -250
- package/src/core/loaders/index.ts +0 -12
- package/src/core/loaders/loader.ts +0 -66
- package/src/core/loaders/object_loader.ts +0 -489
- package/src/core/loaders/query_loader.ts +0 -314
- package/src/core/loaders/raw_count_loader.ts +0 -175
- package/src/core/logger.ts +0 -49
- package/src/core/privacy.ts +0 -660
- package/src/core/query/assoc_query.ts +0 -240
- package/src/core/query/custom_clause_query.ts +0 -174
- package/src/core/query/custom_query.ts +0 -302
- package/src/core/query/index.ts +0 -9
- package/src/core/query/query.ts +0 -674
- package/src/core/query_impl.ts +0 -32
- package/src/core/viewer.ts +0 -52
- package/src/ent.code-workspace +0 -73
- package/src/graphql/builtins/connection.ts +0 -25
- package/src/graphql/builtins/edge.ts +0 -16
- package/src/graphql/builtins/node.ts +0 -12
- package/src/graphql/graphql.ts +0 -891
- package/src/graphql/graphql_field_helpers.ts +0 -221
- package/src/graphql/index.ts +0 -42
- package/src/graphql/mutations/union.ts +0 -39
- package/src/graphql/node_resolver.ts +0 -122
- package/src/graphql/query/connection_type.ts +0 -113
- package/src/graphql/query/edge_connection.ts +0 -171
- package/src/graphql/query/page_info.ts +0 -34
- package/src/graphql/query/shared_edge_connection.ts +0 -287
- package/src/graphql/scalars/orderby_direction.ts +0 -13
- package/src/graphql/scalars/time.ts +0 -38
- package/src/imports/dataz/example1/_auth.ts +0 -51
- package/src/imports/dataz/example1/_viewer.ts +0 -35
- package/src/imports/index.ts +0 -213
- package/src/index.ts +0 -145
- package/src/parse_schema/parse.ts +0 -585
- package/src/schema/base_schema.ts +0 -224
- package/src/schema/field.ts +0 -1087
- package/src/schema/index.ts +0 -53
- package/src/schema/json_field.ts +0 -94
- package/src/schema/schema.ts +0 -1028
- package/src/schema/struct_field.ts +0 -234
- package/src/schema/union_field.ts +0 -105
- package/src/scripts/custom_compiler.ts +0 -331
- package/src/scripts/custom_graphql.ts +0 -550
- package/src/scripts/migrate_v0.1.ts +0 -41
- package/src/scripts/move_types.ts +0 -131
- package/src/scripts/read_schema.ts +0 -67
- package/src/setupPackage.js +0 -42
- package/src/testutils/action/complex_schemas.ts +0 -517
- package/src/testutils/builder.ts +0 -422
- package/src/testutils/context/test_context.ts +0 -25
- package/src/testutils/db/fixture.ts +0 -32
- package/src/testutils/db/temp_db.ts +0 -941
- package/src/testutils/db/value.ts +0 -294
- package/src/testutils/db_mock.ts +0 -351
- package/src/testutils/db_time_zone.ts +0 -40
- package/src/testutils/ent-graphql-tests/index.ts +0 -653
- package/src/testutils/fake_comms.ts +0 -50
- package/src/testutils/fake_data/const.ts +0 -64
- package/src/testutils/fake_data/events_query.ts +0 -145
- package/src/testutils/fake_data/fake_contact.ts +0 -150
- package/src/testutils/fake_data/fake_event.ts +0 -150
- package/src/testutils/fake_data/fake_tag.ts +0 -139
- package/src/testutils/fake_data/fake_user.ts +0 -232
- package/src/testutils/fake_data/index.ts +0 -1
- package/src/testutils/fake_data/internal.ts +0 -8
- package/src/testutils/fake_data/tag_query.ts +0 -56
- package/src/testutils/fake_data/test_helpers.ts +0 -388
- package/src/testutils/fake_data/user_query.ts +0 -524
- package/src/testutils/fake_log.ts +0 -52
- package/src/testutils/mock_date.ts +0 -10
- package/src/testutils/mock_log.ts +0 -39
- package/src/testutils/parse_sql.ts +0 -685
- package/src/testutils/test_edge_global_schema.ts +0 -49
- package/src/testutils/write.ts +0 -70
- package/src/tsc/ast.ts +0 -351
- package/src/tsc/compilerOptions.ts +0 -85
- package/src/tsc/move_generated.ts +0 -191
- package/src/tsc/transform.ts +0 -226
- package/src/tsc/transform_action.ts +0 -224
- package/src/tsc/transform_ent.ts +0 -66
- package/src/tsc/transform_schema.ts +0 -546
- package/tsconfig.json +0 -20
- /package/{dist/action → action}/action.d.ts +0 -0
- /package/{dist/action → action}/action.js +0 -0
- /package/{dist/action → action}/executor.d.ts +0 -0
- /package/{dist/action → action}/executor.js +0 -0
- /package/{dist/action → action}/experimental_action.d.ts +0 -0
- /package/{dist/action → action}/experimental_action.js +0 -0
- /package/{dist/action → action}/index.d.ts +0 -0
- /package/{dist/action → action}/index.js +0 -0
- /package/{dist/action → action}/operations.d.ts +0 -0
- /package/{dist/action → action}/operations.js +0 -0
- /package/{dist/action → action}/orchestrator.d.ts +0 -0
- /package/{dist/action → action}/orchestrator.js +0 -0
- /package/{dist/action → action}/privacy.d.ts +0 -0
- /package/{dist/action → action}/privacy.js +0 -0
- /package/{dist/action → action}/relative_value.d.ts +0 -0
- /package/{dist/action → action}/relative_value.js +0 -0
- /package/{dist/action → action}/transaction.d.ts +0 -0
- /package/{dist/action → action}/transaction.js +0 -0
- /package/{dist/auth → auth}/auth.d.ts +0 -0
- /package/{dist/auth → auth}/auth.js +0 -0
- /package/{dist/auth → auth}/index.d.ts +0 -0
- /package/{dist/auth → auth}/index.js +0 -0
- /package/{dist/core → core}/base.d.ts +0 -0
- /package/{dist/core → core}/base.js +0 -0
- /package/{dist/core → core}/clause.d.ts +0 -0
- /package/{dist/core → core}/clause.js +0 -0
- /package/{dist/core → core}/config.d.ts +0 -0
- /package/{dist/core → core}/config.js +0 -0
- /package/{dist/core → core}/const.d.ts +0 -0
- /package/{dist/core → core}/const.js +0 -0
- /package/{dist/core → core}/context.d.ts +0 -0
- /package/{dist/core → core}/context.js +0 -0
- /package/{dist/core → core}/convert.d.ts +0 -0
- /package/{dist/core → core}/convert.js +0 -0
- /package/{dist/core → core}/date.d.ts +0 -0
- /package/{dist/core → core}/date.js +0 -0
- /package/{dist/core → core}/db.d.ts +0 -0
- /package/{dist/core → core}/db.js +0 -0
- /package/{dist/core → core}/ent.d.ts +0 -0
- /package/{dist/core → core}/ent.js +0 -0
- /package/{dist/core → core}/global_schema.d.ts +0 -0
- /package/{dist/core → core}/global_schema.js +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
- /package/{dist/core → core}/loaders/index.d.ts +0 -0
- /package/{dist/core → core}/loaders/index.js +0 -0
- /package/{dist/core → core}/loaders/loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/loader.js +0 -0
- /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/object_loader.js +0 -0
- /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/query_loader.js +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
- /package/{dist/core → core}/logger.d.ts +0 -0
- /package/{dist/core → core}/logger.js +0 -0
- /package/{dist/core → core}/privacy.d.ts +0 -0
- /package/{dist/core → core}/privacy.js +0 -0
- /package/{dist/core → core}/query/assoc_query.d.ts +0 -0
- /package/{dist/core → core}/query/assoc_query.js +0 -0
- /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_clause_query.js +0 -0
- /package/{dist/core → core}/query/custom_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_query.js +0 -0
- /package/{dist/core → core}/query/index.d.ts +0 -0
- /package/{dist/core → core}/query/index.js +0 -0
- /package/{dist/core → core}/query/query.d.ts +0 -0
- /package/{dist/core → core}/query/query.js +0 -0
- /package/{dist/core → core}/query_impl.d.ts +0 -0
- /package/{dist/core → core}/query_impl.js +0 -0
- /package/{dist/core → core}/viewer.d.ts +0 -0
- /package/{dist/core → core}/viewer.js +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
- /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/node.js +0 -0
- /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql.js +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
- /package/{dist/graphql → graphql}/index.d.ts +0 -0
- /package/{dist/graphql → graphql}/index.js +0 -0
- /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
- /package/{dist/graphql → graphql}/mutations/union.js +0 -0
- /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
- /package/{dist/graphql → graphql}/node_resolver.js +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/page_info.js +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
- /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/time.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
- /package/{dist/imports → imports}/index.d.ts +0 -0
- /package/{dist/imports → imports}/index.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
- /package/{dist/schema → schema}/base_schema.d.ts +0 -0
- /package/{dist/schema → schema}/base_schema.js +0 -0
- /package/{dist/schema → schema}/field.d.ts +0 -0
- /package/{dist/schema → schema}/field.js +0 -0
- /package/{dist/schema → schema}/index.d.ts +0 -0
- /package/{dist/schema → schema}/index.js +0 -0
- /package/{dist/schema → schema}/json_field.d.ts +0 -0
- /package/{dist/schema → schema}/json_field.js +0 -0
- /package/{dist/schema → schema}/schema.d.ts +0 -0
- /package/{dist/schema → schema}/schema.js +0 -0
- /package/{dist/schema → schema}/struct_field.d.ts +0 -0
- /package/{dist/schema → schema}/struct_field.js +0 -0
- /package/{dist/schema → schema}/union_field.d.ts +0 -0
- /package/{dist/schema → schema}/union_field.js +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.js +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.js +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
- /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
- /package/{dist/scripts → scripts}/move_types.js +0 -0
- /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
- /package/{dist/scripts → scripts}/read_schema.js +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
- /package/{dist/testutils → testutils}/builder.d.ts +0 -0
- /package/{dist/testutils → testutils}/builder.js +0 -0
- /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
- /package/{dist/testutils → testutils}/context/test_context.js +0 -0
- /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/fixture.js +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
- /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/value.js +0 -0
- /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_mock.js +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_comms.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_log.js +0 -0
- /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_date.js +0 -0
- /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_log.js +0 -0
- /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
- /package/{dist/testutils → testutils}/parse_sql.js +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
- /package/{dist/testutils → testutils}/write.d.ts +0 -0
- /package/{dist/testutils → testutils}/write.js +0 -0
- /package/{dist/tsc → tsc}/ast.d.ts +0 -0
- /package/{dist/tsc → tsc}/ast.js +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
- /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
- /package/{dist/tsc → tsc}/move_generated.js +0 -0
- /package/{dist/tsc → tsc}/transform.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform.js +0 -0
- /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_action.js +0 -0
- /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_ent.js +0 -0
- /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_schema.js +0 -0
|
@@ -0,0 +1,804 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assocTests = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const ent_1 = require("../ent");
|
|
6
|
+
const viewer_1 = require("../viewer");
|
|
7
|
+
const jest_date_mock_1 = require("jest-date-mock");
|
|
8
|
+
const index_1 = require("../../testutils/fake_data/index");
|
|
9
|
+
const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
|
|
10
|
+
const clause_1 = require("../clause");
|
|
11
|
+
const builder_1 = require("../../testutils/builder");
|
|
12
|
+
const luxon_1 = require("luxon");
|
|
13
|
+
const convert_1 = require("../convert");
|
|
14
|
+
function assocTests(ml, global = false) {
|
|
15
|
+
ml.mock();
|
|
16
|
+
describe("custom edge", () => {
|
|
17
|
+
let user1, user2;
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
user2 = await (0, test_helpers_1.createTestUser)();
|
|
20
|
+
const builder = (0, index_1.getUserBuilder)(new viewer_1.LoggedOutViewer(), (0, test_helpers_1.getUserInput)());
|
|
21
|
+
builder.orchestrator.addOutboundEdge(user2.id, index_1.EdgeType.UserToCustomEdge, index_1.NodeType.FakeUser);
|
|
22
|
+
await builder.saveX();
|
|
23
|
+
user1 = await builder.editedEntX();
|
|
24
|
+
});
|
|
25
|
+
test("ids", async () => {
|
|
26
|
+
const ids = await index_1.UserToCustomEdgeQuery.query(user1.viewer, user1).queryIDs();
|
|
27
|
+
expect(ids.length).toBe(1);
|
|
28
|
+
expect(ids).toEqual([user2.id]);
|
|
29
|
+
});
|
|
30
|
+
test("edges", async () => {
|
|
31
|
+
const edges = await index_1.UserToCustomEdgeQuery.query(user1.viewer, user1).queryEdges();
|
|
32
|
+
expect(edges.length).toBe(1);
|
|
33
|
+
const edge = edges[0];
|
|
34
|
+
expect(edge).toBeInstanceOf(index_1.CustomEdge);
|
|
35
|
+
expect(edge.id1).toBe(user1.id);
|
|
36
|
+
expect(edge.id2).toBe(user2.id);
|
|
37
|
+
expect(edge.edgeType).toBe(index_1.EdgeType.UserToCustomEdge);
|
|
38
|
+
});
|
|
39
|
+
test("id2", async () => {
|
|
40
|
+
const edge = await index_1.UserToCustomEdgeQuery.query(user1.viewer, user1).queryID2(user2.id);
|
|
41
|
+
expect(edge).toBeDefined();
|
|
42
|
+
expect(edge).toBeInstanceOf(index_1.CustomEdge);
|
|
43
|
+
expect(edge.id1).toBe(user1.id);
|
|
44
|
+
expect(edge.id2).toBe(user2.id);
|
|
45
|
+
expect(edge.edgeType).toBe(index_1.EdgeType.UserToCustomEdge);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const N = 2;
|
|
49
|
+
function firstNFilter(q) {
|
|
50
|
+
return q.first(N);
|
|
51
|
+
}
|
|
52
|
+
function firstNEntsFilter(contacts) {
|
|
53
|
+
return contacts.reverse().slice(0, N);
|
|
54
|
+
}
|
|
55
|
+
function getWhereClause(query) {
|
|
56
|
+
let execArray = /^SELECT (.+) FROM (.+) WHERE (.+)?/.exec(query.query);
|
|
57
|
+
return execArray?.[3];
|
|
58
|
+
}
|
|
59
|
+
function verifyQuery({ length = 1, numQueries = 1, limit = (0, ent_1.getDefaultLimit)(), disablePaginationBump = false, }) {
|
|
60
|
+
expect(ml.logs.length).toBe(length);
|
|
61
|
+
for (let i = 0; i < numQueries; i++) {
|
|
62
|
+
const whereClause = getWhereClause(ml.logs[i]);
|
|
63
|
+
let expLimit = disablePaginationBump ? limit : limit + 1;
|
|
64
|
+
if (global) {
|
|
65
|
+
expect(whereClause, `${i}`).toBe(
|
|
66
|
+
// default limit
|
|
67
|
+
`${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", ""), (0, clause_1.Eq)("deleted_at", null)).clause(1)} ORDER BY time DESC, id2 DESC LIMIT ${expLimit}`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
expect(whereClause, `${i}`).toBe(
|
|
71
|
+
// default limit
|
|
72
|
+
`${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", "")).clause(1)} ORDER BY time DESC, id2 DESC LIMIT ${expLimit}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function verifyCountQuery({ length = 1, numQueries = 1 }) {
|
|
77
|
+
expect(ml.logs.length).toBe(length);
|
|
78
|
+
for (let i = 0; i < numQueries; i++) {
|
|
79
|
+
const whereClause = getWhereClause(ml.logs[i]);
|
|
80
|
+
if (global) {
|
|
81
|
+
expect(whereClause).toBe(`${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", ""), (0, clause_1.Eq)("deleted_at", null)).clause(1)}`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
expect(whereClause).toBe(`${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", "")).clause(1)}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// TODO need to test multi-ids with id1s that aren't visible...
|
|
89
|
+
// so 2 user's friend requests at the same time
|
|
90
|
+
class MultiIDsTestQueryFilter {
|
|
91
|
+
constructor(filter, ents, limit) {
|
|
92
|
+
this.filter = filter;
|
|
93
|
+
this.ents = ents;
|
|
94
|
+
this.limit = limit;
|
|
95
|
+
this.dataz = [];
|
|
96
|
+
}
|
|
97
|
+
async beforeEach() {
|
|
98
|
+
let [user1, user2, user3] = await Promise.all([
|
|
99
|
+
(0, test_helpers_1.createAllContacts)({ input: { firstName: "Jon", lastName: "Snow" } }),
|
|
100
|
+
(0, test_helpers_1.createAllContacts)({
|
|
101
|
+
input: { firstName: "Aegon", lastName: "Targaryen" },
|
|
102
|
+
}),
|
|
103
|
+
(0, test_helpers_1.createAllContacts)({ input: { firstName: "Ned", lastName: "Stark" } }),
|
|
104
|
+
]);
|
|
105
|
+
// modify contacts as needed
|
|
106
|
+
user1[1] = this.ents(user1[1]);
|
|
107
|
+
user2[1] = this.ents(user2[1]);
|
|
108
|
+
user3[1] = this.ents(user3[1]);
|
|
109
|
+
this.dataz = [user1, user2, user3];
|
|
110
|
+
ml.clear();
|
|
111
|
+
}
|
|
112
|
+
getQuery(viewer) {
|
|
113
|
+
return this.filter(index_1.UserToContactsQuery.query(viewer || new viewer_1.LoggedOutViewer(), this.dataz.map((data) => data[0])));
|
|
114
|
+
}
|
|
115
|
+
async testIDs() {
|
|
116
|
+
const idsMap = await this.getQuery().queryAllIDs();
|
|
117
|
+
expect(idsMap.size).toBe(this.dataz.length);
|
|
118
|
+
for (let i = 0; i < this.dataz.length; i++) {
|
|
119
|
+
let data = this.dataz[i];
|
|
120
|
+
expect(idsMap.get(data[0].id)).toEqual(data[1].map((contact) => contact.id));
|
|
121
|
+
}
|
|
122
|
+
verifyQuery({
|
|
123
|
+
length: this.dataz.length,
|
|
124
|
+
numQueries: this.dataz.length,
|
|
125
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// rawCount isn't affected by filters...
|
|
129
|
+
async testRawCount() {
|
|
130
|
+
const countMap = await this.getQuery().queryAllRawCount();
|
|
131
|
+
expect(countMap.size).toBe(this.dataz.length);
|
|
132
|
+
for (let i = 0; i < this.dataz.length; i++) {
|
|
133
|
+
let data = this.dataz[i];
|
|
134
|
+
expect(countMap.get(data[0].id)).toStrictEqual(test_helpers_1.inputs.length);
|
|
135
|
+
}
|
|
136
|
+
verifyCountQuery({ numQueries: 3, length: 3 });
|
|
137
|
+
}
|
|
138
|
+
async testCount() {
|
|
139
|
+
const countMap = await this.getQuery().queryAllCount();
|
|
140
|
+
expect(countMap.size).toBe(this.dataz.length);
|
|
141
|
+
for (let i = 0; i < this.dataz.length; i++) {
|
|
142
|
+
let data = this.dataz[i];
|
|
143
|
+
expect(countMap.get(data[0].id)).toStrictEqual(data[1].length);
|
|
144
|
+
}
|
|
145
|
+
verifyQuery({
|
|
146
|
+
length: this.dataz.length,
|
|
147
|
+
numQueries: this.dataz.length,
|
|
148
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async testEdges() {
|
|
152
|
+
const edgesMap = await this.getQuery().queryAllEdges();
|
|
153
|
+
expect(edgesMap.size).toBe(this.dataz.length);
|
|
154
|
+
for (let i = 0; i < this.dataz.length; i++) {
|
|
155
|
+
let data = this.dataz[i];
|
|
156
|
+
(0, test_helpers_1.verifyUserToContactEdges)(data[0], edgesMap.get(data[0].id) || [], data[1]);
|
|
157
|
+
}
|
|
158
|
+
verifyQuery({
|
|
159
|
+
length: this.dataz.length,
|
|
160
|
+
numQueries: this.dataz.length,
|
|
161
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async testEnts() {
|
|
165
|
+
// privacy...
|
|
166
|
+
const entsMap = await this.getQuery().queryAllEnts();
|
|
167
|
+
expect(entsMap.size).toBe(this.dataz.length);
|
|
168
|
+
for (let i = 0; i < this.dataz.length; i++) {
|
|
169
|
+
let data = this.dataz[i];
|
|
170
|
+
(0, test_helpers_1.verifyUserToContacts)(data[0], entsMap.get(data[0].id) || [], []);
|
|
171
|
+
}
|
|
172
|
+
// privacy. only data for the first id is visible in this case
|
|
173
|
+
const entsMap2 = await this.getQuery(new viewer_1.IDViewer(this.dataz[0][0].id)).queryAllEnts();
|
|
174
|
+
expect(entsMap2.size).toBe(this.dataz.length);
|
|
175
|
+
for (let i = 0; i < this.dataz.length; i++) {
|
|
176
|
+
let data = this.dataz[i];
|
|
177
|
+
(0, test_helpers_1.verifyUserToContacts)(data[0], entsMap2.get(data[0].id) || [], i == 0 ? data[1] : []);
|
|
178
|
+
}
|
|
179
|
+
verifyQuery({
|
|
180
|
+
// extra query for the nodes
|
|
181
|
+
// dataz.length twice to fetch the edge data
|
|
182
|
+
// and then twice to fetch all the nodes for the contacts
|
|
183
|
+
length: this.dataz.length + this.dataz.length + this.dataz.length * 2,
|
|
184
|
+
numQueries: this.dataz.length,
|
|
185
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
describe("multi-ids", () => {
|
|
190
|
+
const filter = new MultiIDsTestQueryFilter((q) => {
|
|
191
|
+
// no filters
|
|
192
|
+
return q;
|
|
193
|
+
}, (contacts) => {
|
|
194
|
+
// nothing to do here
|
|
195
|
+
// reverse because edges are most recent first
|
|
196
|
+
return contacts.reverse();
|
|
197
|
+
});
|
|
198
|
+
beforeEach(async () => {
|
|
199
|
+
await filter.beforeEach();
|
|
200
|
+
});
|
|
201
|
+
test("ids", async () => {
|
|
202
|
+
await filter.testIDs();
|
|
203
|
+
});
|
|
204
|
+
test("rawCount", async () => {
|
|
205
|
+
await filter.testRawCount();
|
|
206
|
+
});
|
|
207
|
+
test("count", async () => {
|
|
208
|
+
await filter.testCount();
|
|
209
|
+
});
|
|
210
|
+
test("edges", async () => {
|
|
211
|
+
await filter.testEdges();
|
|
212
|
+
});
|
|
213
|
+
test("ents", async () => {
|
|
214
|
+
await filter.testEnts();
|
|
215
|
+
});
|
|
216
|
+
test("id2", async () => {
|
|
217
|
+
// const users = filter.dataz.map((data) => data[0]);
|
|
218
|
+
for (let i = 0; i < filter.dataz.length; i++) {
|
|
219
|
+
const id1 = filter.dataz[i][0].id;
|
|
220
|
+
// get user that corresponds to position
|
|
221
|
+
const query = filter.getQuery(new viewer_1.IDViewer(id1));
|
|
222
|
+
const id2 = filter.dataz[i][1][0].id;
|
|
223
|
+
//get first contact for user
|
|
224
|
+
const m = await query.queryAllID2(id2);
|
|
225
|
+
for (let j = 0; j < filter.dataz.length; j++) {
|
|
226
|
+
const edge = m.get(filter.dataz[j][0].id);
|
|
227
|
+
if (i == j) {
|
|
228
|
+
expect(edge).toBeDefined();
|
|
229
|
+
expect(edge).toBeInstanceOf(ent_1.AssocEdge);
|
|
230
|
+
expect(edge.id1).toBe(id1);
|
|
231
|
+
expect(edge.id2).toBe(id2);
|
|
232
|
+
expect(edge.edgeType).toBe(index_1.EdgeType.UserToContacts);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
expect(edge).toBeUndefined();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe("multi-ids. firstN", () => {
|
|
242
|
+
const filter = new MultiIDsTestQueryFilter(firstNFilter, firstNEntsFilter, 2);
|
|
243
|
+
beforeEach(async () => {
|
|
244
|
+
await filter.beforeEach();
|
|
245
|
+
});
|
|
246
|
+
test("ids", async () => {
|
|
247
|
+
await filter.testIDs();
|
|
248
|
+
});
|
|
249
|
+
test("rawCount", async () => {
|
|
250
|
+
await filter.testRawCount();
|
|
251
|
+
});
|
|
252
|
+
test("count", async () => {
|
|
253
|
+
await filter.testCount();
|
|
254
|
+
});
|
|
255
|
+
test("edges", async () => {
|
|
256
|
+
await filter.testEdges();
|
|
257
|
+
});
|
|
258
|
+
test("ents", async () => {
|
|
259
|
+
await filter.testEnts();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
class ChainTestQueryFilter {
|
|
263
|
+
constructor(initialQuery, subsequentQueries, filter, lastHopFilter) {
|
|
264
|
+
this.initialQuery = initialQuery;
|
|
265
|
+
this.subsequentQueries = subsequentQueries;
|
|
266
|
+
this.filter = filter;
|
|
267
|
+
this.lastHopFilter = lastHopFilter;
|
|
268
|
+
}
|
|
269
|
+
async beforeEach() {
|
|
270
|
+
this.user = await (0, test_helpers_1.createTestUser)();
|
|
271
|
+
this.event = await (0, test_helpers_1.createTestEvent)(this.user);
|
|
272
|
+
this.event2 = await (0, test_helpers_1.createTestEvent)(this.user, { title: "Red Wedding" });
|
|
273
|
+
this.friends = await Promise.all(test_helpers_1.inputs.map(async (input) => {
|
|
274
|
+
// just to make times deterministic so that tests can consistently work
|
|
275
|
+
(0, jest_date_mock_1.advanceBy)(100);
|
|
276
|
+
const builder = (0, index_1.getUserBuilder)(this.user.viewer, (0, test_helpers_1.getUserInput)(input));
|
|
277
|
+
// add edge from user to contact
|
|
278
|
+
builder.orchestrator.addOutboundEdge(this.user.id, index_1.EdgeType.UserToFriends, index_1.NodeType.FakeUser, {
|
|
279
|
+
time: new Date(), // set time to advanceBy time
|
|
280
|
+
});
|
|
281
|
+
// all invited and all attending
|
|
282
|
+
builder.orchestrator.addInboundEdge(this.event.id, index_1.EdgeType.EventToInvited, "Event");
|
|
283
|
+
builder.orchestrator.addInboundEdge(this.event.id, index_1.EdgeType.EventToAttendees, index_1.NodeType.FakeEvent);
|
|
284
|
+
// Robb also attending the red wedding
|
|
285
|
+
if (input.firstName === "Robb") {
|
|
286
|
+
builder.orchestrator.addInboundEdge(this.event2.id, index_1.EdgeType.EventToInvited, index_1.NodeType.FakeEvent);
|
|
287
|
+
builder.orchestrator.addInboundEdge(this.event2.id, index_1.EdgeType.EventToAttendees, index_1.NodeType.FakeEvent);
|
|
288
|
+
}
|
|
289
|
+
await builder.saveX();
|
|
290
|
+
return await builder.editedEntX();
|
|
291
|
+
}));
|
|
292
|
+
expect(this.friends.length).toBe(test_helpers_1.inputs.length);
|
|
293
|
+
const count = await index_1.UserToFriendsQuery.query(new viewer_1.IDViewer(this.user.id), this.user.id).queryCount();
|
|
294
|
+
expect(count).toStrictEqual(test_helpers_1.inputs.length);
|
|
295
|
+
}
|
|
296
|
+
getQuery(vc) {
|
|
297
|
+
return this.filter(new this.initialQuery(vc, this.user.id));
|
|
298
|
+
}
|
|
299
|
+
async compare(fn, comparer) {
|
|
300
|
+
const vc = new viewer_1.IDViewer(this.user.id);
|
|
301
|
+
const oneHopResult = await fn(this.getQuery(vc));
|
|
302
|
+
const queries = [this.initialQuery, ...this.subsequentQueries];
|
|
303
|
+
let last = [this.user.id];
|
|
304
|
+
let allHopsResult;
|
|
305
|
+
for (let i = 0; i < queries.length; i++) {
|
|
306
|
+
let queryCtr = queries[i];
|
|
307
|
+
let query = new queryCtr(vc, last);
|
|
308
|
+
if (this.lastHopFilter && i + 1 == queries.length - 1) {
|
|
309
|
+
query = this.lastHopFilter(query);
|
|
310
|
+
}
|
|
311
|
+
if (i === queries.length - 1) {
|
|
312
|
+
allHopsResult = await fn(query);
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
let result = await query.queryAllIDs();
|
|
316
|
+
last = [];
|
|
317
|
+
for (const [_, ids] of result) {
|
|
318
|
+
last.push(...ids);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (comparer) {
|
|
322
|
+
comparer(oneHopResult, allHopsResult);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
expect(oneHopResult).toStrictEqual(allHopsResult);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async testIDs() {
|
|
329
|
+
await this.compare((q) => q.queryAllIDs());
|
|
330
|
+
}
|
|
331
|
+
async testCount() {
|
|
332
|
+
await this.compare((q) => q.queryAllCount());
|
|
333
|
+
}
|
|
334
|
+
async testRawCount() {
|
|
335
|
+
await this.compare((q) => q.queryAllRawCount());
|
|
336
|
+
}
|
|
337
|
+
async testEdges() {
|
|
338
|
+
await this.compare((q) => q.queryAllEdges());
|
|
339
|
+
}
|
|
340
|
+
async testEnts() {
|
|
341
|
+
function compare(oneHop, allHops) {
|
|
342
|
+
expect(allHops.size).toEqual(oneHop.size);
|
|
343
|
+
for (const [key, ents] of allHops) {
|
|
344
|
+
expect(oneHop.has(key)).toEqual(true);
|
|
345
|
+
const oneHopEnts = oneHop.get(key);
|
|
346
|
+
for (let i = 0; i < ents.length; i++) {
|
|
347
|
+
expect(oneHopEnts[i].id).toEqual(ents[i].id);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
await this.compare((q) => q.queryAllEnts(), compare);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
describe("chained queries 2 steps", () => {
|
|
355
|
+
const filter = new ChainTestQueryFilter(index_1.UserToFriendsQuery, [index_1.UserToEventsAttendingQuery], (q) => {
|
|
356
|
+
return q.queryEventsAttending();
|
|
357
|
+
});
|
|
358
|
+
beforeEach(async () => {
|
|
359
|
+
await filter.beforeEach();
|
|
360
|
+
});
|
|
361
|
+
test("ids", async () => {
|
|
362
|
+
await filter.testIDs();
|
|
363
|
+
});
|
|
364
|
+
test("count", async () => {
|
|
365
|
+
await filter.testCount();
|
|
366
|
+
});
|
|
367
|
+
test("rawCount", async () => {
|
|
368
|
+
await filter.testRawCount();
|
|
369
|
+
});
|
|
370
|
+
test("edges", async () => {
|
|
371
|
+
await filter.testEdges();
|
|
372
|
+
});
|
|
373
|
+
test("ents", async () => {
|
|
374
|
+
await filter.testEnts();
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
describe("chained queries 2 steps w/ filter", () => {
|
|
378
|
+
const filter = new ChainTestQueryFilter(index_1.UserToFriendsQuery, [index_1.UserToEventsAttendingQuery], (q) => {
|
|
379
|
+
return q.first(2).queryEventsAttending();
|
|
380
|
+
}, (q) => {
|
|
381
|
+
return q.first(2);
|
|
382
|
+
});
|
|
383
|
+
beforeEach(async () => {
|
|
384
|
+
await filter.beforeEach();
|
|
385
|
+
});
|
|
386
|
+
test("ids", async () => {
|
|
387
|
+
await filter.testIDs();
|
|
388
|
+
});
|
|
389
|
+
test("count", async () => {
|
|
390
|
+
await filter.testCount();
|
|
391
|
+
});
|
|
392
|
+
test("rawCount", async () => {
|
|
393
|
+
await filter.testRawCount();
|
|
394
|
+
});
|
|
395
|
+
test("edges", async () => {
|
|
396
|
+
await filter.testEdges();
|
|
397
|
+
});
|
|
398
|
+
test("ents", async () => {
|
|
399
|
+
await filter.testEnts();
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
describe("chained queries 3 steps", () => {
|
|
403
|
+
const filter = new ChainTestQueryFilter(index_1.UserToFriendsQuery, [index_1.UserToEventsAttendingQuery, index_1.EventToHostsQuery], (q) => {
|
|
404
|
+
return q.queryEventsAttending().queryHosts();
|
|
405
|
+
});
|
|
406
|
+
beforeEach(async () => {
|
|
407
|
+
await filter.beforeEach();
|
|
408
|
+
});
|
|
409
|
+
test("ids", async () => {
|
|
410
|
+
await filter.testIDs();
|
|
411
|
+
});
|
|
412
|
+
test("count", async () => {
|
|
413
|
+
await filter.testCount();
|
|
414
|
+
});
|
|
415
|
+
test("rawCount", async () => {
|
|
416
|
+
await filter.testRawCount();
|
|
417
|
+
});
|
|
418
|
+
test("edges", async () => {
|
|
419
|
+
await filter.testEdges();
|
|
420
|
+
});
|
|
421
|
+
test("ents", async () => {
|
|
422
|
+
await filter.testEnts();
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
class PolymorphicID2sTestQueryFilter {
|
|
426
|
+
constructor(filter, ents, limit) {
|
|
427
|
+
this.filter = filter;
|
|
428
|
+
this.ents = ents;
|
|
429
|
+
this.limit = limit;
|
|
430
|
+
this.users = [];
|
|
431
|
+
this.events = [];
|
|
432
|
+
}
|
|
433
|
+
async beforeEach() {
|
|
434
|
+
this.users = [];
|
|
435
|
+
this.events = [];
|
|
436
|
+
this.user = await (0, test_helpers_1.createTestUser)();
|
|
437
|
+
for (let i = 0; i < 5; i++) {
|
|
438
|
+
(0, jest_date_mock_1.advanceBy)(100);
|
|
439
|
+
const builder = (0, index_1.getUserBuilder)(this.user.viewer, (0, test_helpers_1.getUserInput)());
|
|
440
|
+
builder.orchestrator.addOutboundEdge(this.user.id, index_1.EdgeType.ObjectToFollowedUsers, index_1.NodeType.FakeUser);
|
|
441
|
+
await builder.saveX();
|
|
442
|
+
const user2 = await builder.editedEntX();
|
|
443
|
+
this.users.push(user2);
|
|
444
|
+
}
|
|
445
|
+
for (let i = 0; i < 5; i++) {
|
|
446
|
+
(0, jest_date_mock_1.advanceBy)(100);
|
|
447
|
+
const builder = (0, index_1.getEventBuilder)(this.user.viewer, (0, test_helpers_1.getEventInput)(this.user));
|
|
448
|
+
builder.orchestrator.addOutboundEdge(this.user.id, index_1.EdgeType.ObjectToFollowedUsers, index_1.NodeType.FakeUser);
|
|
449
|
+
await builder.saveX();
|
|
450
|
+
const event = await builder.editedEntX();
|
|
451
|
+
this.events.push(event);
|
|
452
|
+
}
|
|
453
|
+
//order is users, then events
|
|
454
|
+
this.expCount = this.ents([...this.users, ...this.events]).length;
|
|
455
|
+
ml.clear();
|
|
456
|
+
}
|
|
457
|
+
getQuery(viewer) {
|
|
458
|
+
return this.filter(index_1.UserToFollowingQuery.query(viewer || new viewer_1.IDViewer(this.user.id), this.user));
|
|
459
|
+
}
|
|
460
|
+
async testIDs() {
|
|
461
|
+
const ids = await this.getQuery().queryIDs();
|
|
462
|
+
expect(ids.length).toBe(this.expCount);
|
|
463
|
+
const expIDs = this.users
|
|
464
|
+
.map((user) => user.id)
|
|
465
|
+
.concat(this.events.map((event) => event.id))
|
|
466
|
+
.reverse();
|
|
467
|
+
expect(expIDs).toEqual(ids);
|
|
468
|
+
verifyQuery({
|
|
469
|
+
length: 1,
|
|
470
|
+
numQueries: 1,
|
|
471
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
// rawCount isn't affected by filters...
|
|
475
|
+
async testRawCount() {
|
|
476
|
+
const count = await this.getQuery().queryRawCount();
|
|
477
|
+
expect(count).toBe(this.expCount);
|
|
478
|
+
verifyCountQuery({ numQueries: 1, length: 1 });
|
|
479
|
+
}
|
|
480
|
+
async testCount() {
|
|
481
|
+
const count = await this.getQuery().queryCount();
|
|
482
|
+
expect(count).toBe(this.expCount);
|
|
483
|
+
verifyQuery({
|
|
484
|
+
length: 1,
|
|
485
|
+
numQueries: 1,
|
|
486
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
async testEdges() {
|
|
490
|
+
const edges = await this.getQuery().queryEdges();
|
|
491
|
+
expect(edges.length).toBe(this.expCount);
|
|
492
|
+
let userCount = 0;
|
|
493
|
+
let eventCount = 0;
|
|
494
|
+
edges.forEach((edge) => {
|
|
495
|
+
if (edge.id2Type === index_1.NodeType.FakeEvent) {
|
|
496
|
+
eventCount++;
|
|
497
|
+
}
|
|
498
|
+
if (edge.id2Type === index_1.NodeType.FakeUser) {
|
|
499
|
+
userCount++;
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
expect(userCount).toBe(this.expCount / 2);
|
|
503
|
+
expect(eventCount).toBe(this.expCount / 2);
|
|
504
|
+
verifyQuery({
|
|
505
|
+
length: 1,
|
|
506
|
+
numQueries: 1,
|
|
507
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
async testEnts() {
|
|
511
|
+
// privacy...
|
|
512
|
+
const ents = await this.getQuery().queryEnts();
|
|
513
|
+
expect(ents.length).toBe(this.expCount);
|
|
514
|
+
let userCount = 0;
|
|
515
|
+
let eventCount = 0;
|
|
516
|
+
ents.forEach((ent) => {
|
|
517
|
+
if (ent instanceof index_1.FakeEvent) {
|
|
518
|
+
eventCount++;
|
|
519
|
+
}
|
|
520
|
+
if (ent instanceof index_1.FakeUser) {
|
|
521
|
+
userCount++;
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
expect(userCount).toBe(this.expCount / 2);
|
|
525
|
+
expect(eventCount).toBe(this.expCount / 2);
|
|
526
|
+
// when doing privacy checks, hard to say what will be fetched
|
|
527
|
+
// verifyQuery({
|
|
528
|
+
// // 1 for edges, 1 for users, 1 for events
|
|
529
|
+
// length: 3,
|
|
530
|
+
// numQueries: 3,
|
|
531
|
+
// limit: this.limit || getDefaultLimit(),
|
|
532
|
+
// });
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
describe("polymorphic id2s", () => {
|
|
536
|
+
const filter = new PolymorphicID2sTestQueryFilter((q) => {
|
|
537
|
+
// no filters
|
|
538
|
+
return q;
|
|
539
|
+
}, (ents) => {
|
|
540
|
+
// nothing to do here
|
|
541
|
+
// reverse because edges are most recent first
|
|
542
|
+
return ents.reverse();
|
|
543
|
+
});
|
|
544
|
+
// TODO not working when it's a beforeAll
|
|
545
|
+
// working with beforeEach but we should only need to create this data once
|
|
546
|
+
beforeEach(async () => {
|
|
547
|
+
await filter.beforeEach();
|
|
548
|
+
});
|
|
549
|
+
test("ids", async () => {
|
|
550
|
+
await filter.testIDs();
|
|
551
|
+
});
|
|
552
|
+
test("rawCount", async () => {
|
|
553
|
+
await filter.testRawCount();
|
|
554
|
+
});
|
|
555
|
+
test("count", async () => {
|
|
556
|
+
await filter.testCount();
|
|
557
|
+
});
|
|
558
|
+
test("edges", async () => {
|
|
559
|
+
await filter.testEdges();
|
|
560
|
+
});
|
|
561
|
+
test("ents", async () => {
|
|
562
|
+
await filter.testEnts();
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
describe("privacy", () => {
|
|
566
|
+
let user;
|
|
567
|
+
let friendRequests;
|
|
568
|
+
let user2;
|
|
569
|
+
beforeEach(async () => {
|
|
570
|
+
[user, friendRequests] = await (0, test_helpers_1.createUserPlusFriendRequests)();
|
|
571
|
+
user2 = await (0, test_helpers_1.createTestUser)();
|
|
572
|
+
});
|
|
573
|
+
function getQuery(viewer) {
|
|
574
|
+
return index_1.UserToIncomingFriendRequestsQuery.query(viewer, user.id);
|
|
575
|
+
}
|
|
576
|
+
test("ids", async () => {
|
|
577
|
+
const ids = await getQuery(user2.viewer).queryIDs();
|
|
578
|
+
expect(ids.length).toBe(0);
|
|
579
|
+
const idsFromUser = await getQuery(user.viewer).queryIDs();
|
|
580
|
+
expect(idsFromUser.length).toBe(friendRequests.length);
|
|
581
|
+
});
|
|
582
|
+
test("count", async () => {
|
|
583
|
+
const count = await getQuery(user2.viewer).queryCount();
|
|
584
|
+
expect(count).toBe(0);
|
|
585
|
+
const countFromUser = await getQuery(user.viewer).queryCount();
|
|
586
|
+
expect(countFromUser).toBe(friendRequests.length);
|
|
587
|
+
});
|
|
588
|
+
test("rawCount", async () => {
|
|
589
|
+
const rawCount = await getQuery(user2.viewer).queryRawCount();
|
|
590
|
+
expect(rawCount).toBe(0);
|
|
591
|
+
const rawCountFromUser = await getQuery(user.viewer).queryRawCount();
|
|
592
|
+
expect(rawCountFromUser).toBe(friendRequests.length);
|
|
593
|
+
});
|
|
594
|
+
test("edges", async () => {
|
|
595
|
+
const edges = await getQuery(user2.viewer).queryEdges();
|
|
596
|
+
expect(edges.length).toBe(0);
|
|
597
|
+
const edgesFromUser = await getQuery(user.viewer).queryEdges();
|
|
598
|
+
expect(edgesFromUser.length).toBe(friendRequests.length);
|
|
599
|
+
});
|
|
600
|
+
test("ents", async () => {
|
|
601
|
+
const ents = await getQuery(user2.viewer).queryEnts();
|
|
602
|
+
expect(ents.length).toBe(0);
|
|
603
|
+
const entsFromUser = await getQuery(user.viewer).queryEnts();
|
|
604
|
+
expect(entsFromUser.length).toBe(0);
|
|
605
|
+
const entsFromUserVCToken = await getQuery(new index_1.ViewerWithAccessToken(user.id, {
|
|
606
|
+
tokens: {
|
|
607
|
+
allow_incoming_friend_request: true,
|
|
608
|
+
},
|
|
609
|
+
})).queryEnts();
|
|
610
|
+
expect(entsFromUserVCToken.length).toBe(friendRequests.length);
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
describe("multi-ids privacy", () => {
|
|
614
|
+
let user;
|
|
615
|
+
let friendRequests;
|
|
616
|
+
let user2;
|
|
617
|
+
beforeEach(async () => {
|
|
618
|
+
[user, friendRequests] = await (0, test_helpers_1.createUserPlusFriendRequests)();
|
|
619
|
+
[user2] = await (0, test_helpers_1.createUserPlusFriendRequests)();
|
|
620
|
+
});
|
|
621
|
+
function getQuery(viewer) {
|
|
622
|
+
return index_1.UserToIncomingFriendRequestsQuery.query(viewer || user.viewer, [
|
|
623
|
+
user.id,
|
|
624
|
+
user2.id,
|
|
625
|
+
]);
|
|
626
|
+
}
|
|
627
|
+
test("ids", async () => {
|
|
628
|
+
const idsMap = await getQuery().queryAllIDs();
|
|
629
|
+
expect(idsMap.size).toBe(2);
|
|
630
|
+
expect(idsMap.get(user.id)?.length).toBe(friendRequests.length);
|
|
631
|
+
expect(idsMap.get(user2.id)?.length).toBe(0);
|
|
632
|
+
});
|
|
633
|
+
test("count", async () => {
|
|
634
|
+
const countMap = await getQuery().queryAllCount();
|
|
635
|
+
expect(countMap.size).toBe(2);
|
|
636
|
+
expect(countMap.get(user.id)).toBe(friendRequests.length);
|
|
637
|
+
expect(countMap.get(user2.id)).toBe(0);
|
|
638
|
+
});
|
|
639
|
+
test("raw count", async () => {
|
|
640
|
+
const countMap = await getQuery().queryAllRawCount();
|
|
641
|
+
expect(countMap.size).toBe(2);
|
|
642
|
+
expect(countMap.get(user.id)).toBe(friendRequests.length);
|
|
643
|
+
expect(countMap.get(user2.id)).toBe(0);
|
|
644
|
+
});
|
|
645
|
+
test("edges", async () => {
|
|
646
|
+
const edgesMap = await getQuery().queryAllEdges();
|
|
647
|
+
expect(edgesMap.size).toBe(2);
|
|
648
|
+
expect(edgesMap.get(user.id)?.length).toBe(friendRequests.length);
|
|
649
|
+
expect(edgesMap.get(user2.id)?.length).toBe(0);
|
|
650
|
+
});
|
|
651
|
+
test("ents", async () => {
|
|
652
|
+
const entsMap = await getQuery().queryAllEnts();
|
|
653
|
+
expect(entsMap.size).toBe(2);
|
|
654
|
+
expect(entsMap.get(user.id)?.length).toBe(0);
|
|
655
|
+
expect(entsMap.get(user2.id)?.length).toBe(0);
|
|
656
|
+
const entsMapFromUserVCToken = await getQuery(new index_1.ViewerWithAccessToken(user.id, {
|
|
657
|
+
tokens: {
|
|
658
|
+
allow_incoming_friend_request: true,
|
|
659
|
+
},
|
|
660
|
+
})).queryAllEnts();
|
|
661
|
+
expect(entsMapFromUserVCToken.size).toBe(2);
|
|
662
|
+
expect(entsMapFromUserVCToken.get(user.id)?.length).toBe(friendRequests.length);
|
|
663
|
+
expect(entsMapFromUserVCToken.get(user2.id)?.length).toBe(0);
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
if (!global) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
// global only tests here
|
|
670
|
+
describe("deleted edges", () => {
|
|
671
|
+
let user;
|
|
672
|
+
let friendRequests;
|
|
673
|
+
let user2;
|
|
674
|
+
let postDeletedCount;
|
|
675
|
+
beforeEach(async () => {
|
|
676
|
+
[user, friendRequests] = await (0, test_helpers_1.createUserPlusFriendRequests)();
|
|
677
|
+
user2 = await (0, test_helpers_1.createTestUser)();
|
|
678
|
+
postDeletedCount = Math.floor(friendRequests.length / 2);
|
|
679
|
+
});
|
|
680
|
+
async function deleteEdges() {
|
|
681
|
+
const action = new builder_1.SimpleAction(user.viewer, index_1.FakeUserSchema, new Map(), base_1.WriteOperation.Edit, user);
|
|
682
|
+
for (let i = 0; i < friendRequests.length; i++) {
|
|
683
|
+
if (i % 2 == 0) {
|
|
684
|
+
action.builder.orchestrator.removeInboundEdge(friendRequests[i].id, index_1.EdgeType.UserToFriendRequests);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
await action.saveX();
|
|
688
|
+
}
|
|
689
|
+
function getQuery(viewer) {
|
|
690
|
+
return index_1.UserToIncomingFriendRequestsQuery.query(viewer, user.id);
|
|
691
|
+
}
|
|
692
|
+
test("ids", async () => {
|
|
693
|
+
const ids = await getQuery(user.viewer).queryIDs();
|
|
694
|
+
expect(ids.length).toBe(friendRequests.length);
|
|
695
|
+
});
|
|
696
|
+
test("ids after deleted", async () => {
|
|
697
|
+
await deleteEdges();
|
|
698
|
+
const idsFromUser = await getQuery(user.viewer).queryIDs();
|
|
699
|
+
expect(idsFromUser.length).toBe(postDeletedCount);
|
|
700
|
+
});
|
|
701
|
+
test("ids deleted. fetch deleted anyways", async () => {
|
|
702
|
+
await deleteEdges();
|
|
703
|
+
const idsFromUser = await getQuery(user.viewer)
|
|
704
|
+
.withoutTransformations()
|
|
705
|
+
.queryIDs();
|
|
706
|
+
expect(idsFromUser.length).toBe(friendRequests.length);
|
|
707
|
+
});
|
|
708
|
+
test("count", async () => {
|
|
709
|
+
const count = await getQuery(user.viewer).queryCount();
|
|
710
|
+
expect(count).toBe(friendRequests.length);
|
|
711
|
+
});
|
|
712
|
+
test("count after deleted", async () => {
|
|
713
|
+
await deleteEdges();
|
|
714
|
+
const count = await getQuery(user.viewer).queryCount();
|
|
715
|
+
expect(count).toBe(postDeletedCount);
|
|
716
|
+
});
|
|
717
|
+
test("count after deleted. fetch deleted", async () => {
|
|
718
|
+
await deleteEdges();
|
|
719
|
+
const count = await getQuery(user.viewer)
|
|
720
|
+
.withoutTransformations()
|
|
721
|
+
.queryCount();
|
|
722
|
+
expect(count).toBe(friendRequests.length);
|
|
723
|
+
});
|
|
724
|
+
test("raw count", async () => {
|
|
725
|
+
const count = await getQuery(user.viewer).queryCount();
|
|
726
|
+
expect(count).toBe(friendRequests.length);
|
|
727
|
+
});
|
|
728
|
+
test("raw count after deleted", async () => {
|
|
729
|
+
await deleteEdges();
|
|
730
|
+
const count = await getQuery(user.viewer).queryRawCount();
|
|
731
|
+
expect(count).toBe(postDeletedCount);
|
|
732
|
+
});
|
|
733
|
+
test("raw count after deleted. fetch deleted", async () => {
|
|
734
|
+
await deleteEdges();
|
|
735
|
+
const count = await getQuery(user.viewer)
|
|
736
|
+
.withoutTransformations()
|
|
737
|
+
.queryRawCount();
|
|
738
|
+
expect(count).toBe(friendRequests.length);
|
|
739
|
+
});
|
|
740
|
+
test("edges", async () => {
|
|
741
|
+
const edges = await getQuery(user.viewer).queryEdges();
|
|
742
|
+
expect(edges.length).toBe(friendRequests.length);
|
|
743
|
+
for (const edge of edges) {
|
|
744
|
+
expect(edge.deleted_at).toBeNull();
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
test("edges after deleted", async () => {
|
|
748
|
+
await deleteEdges();
|
|
749
|
+
const edges = await getQuery(user.viewer).queryEdges();
|
|
750
|
+
expect(edges.length).toBe(postDeletedCount);
|
|
751
|
+
for (const edge of edges) {
|
|
752
|
+
expect(edge.deleted_at).toBeNull();
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
test("edges after deleted. fetch deleted", async () => {
|
|
756
|
+
await deleteEdges();
|
|
757
|
+
const edges = await getQuery(user.viewer)
|
|
758
|
+
.withoutTransformations()
|
|
759
|
+
.queryEdges();
|
|
760
|
+
expect(edges.length).toBe(friendRequests.length);
|
|
761
|
+
let notDeletedAtCt = 0;
|
|
762
|
+
for (const edge of edges) {
|
|
763
|
+
if (edge.deleted_at === null) {
|
|
764
|
+
notDeletedAtCt++;
|
|
765
|
+
}
|
|
766
|
+
else {
|
|
767
|
+
expect(luxon_1.DateTime.fromJSDate((0, convert_1.convertDate)(edge.deleted_at)).isValid).toBe(true);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
expect(notDeletedAtCt).toBe(postDeletedCount);
|
|
771
|
+
});
|
|
772
|
+
test("ents", async () => {
|
|
773
|
+
const viewer = new index_1.ViewerWithAccessToken(user.id, {
|
|
774
|
+
tokens: {
|
|
775
|
+
allow_incoming_friend_request: true,
|
|
776
|
+
},
|
|
777
|
+
});
|
|
778
|
+
const ents = await getQuery(viewer).queryEnts();
|
|
779
|
+
expect(ents.length).toBe(friendRequests.length);
|
|
780
|
+
});
|
|
781
|
+
test("ents after deleted", async () => {
|
|
782
|
+
await deleteEdges();
|
|
783
|
+
const viewer = new index_1.ViewerWithAccessToken(user.id, {
|
|
784
|
+
tokens: {
|
|
785
|
+
allow_incoming_friend_request: true,
|
|
786
|
+
},
|
|
787
|
+
});
|
|
788
|
+
const ents = await getQuery(viewer).queryEnts();
|
|
789
|
+
expect(ents.length).toBe(postDeletedCount);
|
|
790
|
+
});
|
|
791
|
+
test("ents after deleted. fetch deleted", async () => {
|
|
792
|
+
await deleteEdges();
|
|
793
|
+
const viewer = new index_1.ViewerWithAccessToken(user.id, {
|
|
794
|
+
tokens: {
|
|
795
|
+
allow_incoming_friend_request: true,
|
|
796
|
+
always_allow_user: true,
|
|
797
|
+
},
|
|
798
|
+
});
|
|
799
|
+
const ents = await getQuery(viewer).withoutTransformations().queryEnts();
|
|
800
|
+
expect(ents.length).toBe(friendRequests.length);
|
|
801
|
+
});
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
exports.assocTests = assocTests;
|