|
1 | | -import { Company, User } from "../../Assets/Entities"; |
| 1 | +import { Company, Order, User } from "../../Assets/Entities"; |
2 | 2 | import * as assert from "assert"; |
3 | 3 | import { testContext, disposeTestDocumentStore } from "../../Utils/TestUtil"; |
4 | 4 |
|
@@ -199,6 +199,49 @@ describe("SubscriptionsBasicTest", function () { |
199 | 199 | } |
200 | 200 | }); |
201 | 201 |
|
| 202 | + it("can handle nested object types correctly", async function() { |
| 203 | + const id = await store.subscriptions.create(Order); |
| 204 | + |
| 205 | + const subscription = store.subscriptions.getSubscriptionWorker<Order>({ |
| 206 | + subscriptionName: id, |
| 207 | + documentType: Order, |
| 208 | + maxErroneousPeriod: 0, |
| 209 | + timeToWaitBeforeConnectionRetry: 0 |
| 210 | + }); |
| 211 | + |
| 212 | + const orders = new AsyncQueue<Order>(); |
| 213 | + |
| 214 | + { |
| 215 | + const session = store.openSession(); |
| 216 | + const order = new Order(); |
| 217 | + order.company = "company/1"; |
| 218 | + order.orderedAt = new Date(); |
| 219 | + await session.store(order, "orders/1"); |
| 220 | + await session.saveChanges(); |
| 221 | + } |
| 222 | + |
| 223 | + subscription.on("batch", (batch, callback) => { |
| 224 | + batch.items.forEach(x => { |
| 225 | + orders.push(x.result); |
| 226 | + }); |
| 227 | + callback(); |
| 228 | + }); |
| 229 | + |
| 230 | + try { |
| 231 | + await Promise.race([ subscriptionFailed(subscription), assertResults() ]); |
| 232 | + } finally { |
| 233 | + subscription.dispose(); |
| 234 | + } |
| 235 | + |
| 236 | + async function assertResults() { |
| 237 | + const firstOrder = await orders.poll(_reasonableWaitTime); |
| 238 | + assertThat(firstOrder instanceof Order) |
| 239 | + .isTrue(); |
| 240 | + assertThat(firstOrder.orderedAt instanceof Date) |
| 241 | + .isTrue(); |
| 242 | + } |
| 243 | + }) |
| 244 | + |
202 | 245 | it("should send all new and modified docs", async function() { |
203 | 246 | const id = await store.subscriptions.create(User); |
204 | 247 |
|
@@ -427,7 +470,7 @@ describe("SubscriptionsBasicTest", function () { |
427 | 470 | subscriptionFailed(allSubscription), |
428 | 471 | subscriptionFailed(filteredUsersSubscription) |
429 | 472 | ]); |
430 | | - |
| 473 | + |
431 | 474 | assert.ok(!usersDocs); |
432 | 475 | } finally { |
433 | 476 | filteredUsersSubscription.dispose(); |
@@ -822,7 +865,7 @@ describe("SubscriptionsBasicTest", function () { |
822 | 865 |
|
823 | 866 | await session.saveChanges(); |
824 | 867 | } |
825 | | - |
| 868 | + |
826 | 869 | const id = await store2.subscriptions.create({ |
827 | 870 | query: "from test" |
828 | 871 | }); |
|
0 commit comments