|
| 1 | +/* |
| 2 | + * Copyright 2018 NEM |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { expect } from 'chai'; |
| 18 | +import { toArray } from 'rxjs/operators'; |
| 19 | +import { ReceiptHttp } from '../../src/infrastructure/infrastructure'; |
| 20 | +import { ReceiptPaginationStreamer } from '../../src/infrastructure/paginationStreamer/ReceiptPaginationStreamer'; |
| 21 | +import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; |
| 22 | +import { ReceiptType, UInt64 } from '../../src/model/model'; |
| 23 | +import { IntegrationTestHelper } from './IntegrationTestHelper'; |
| 24 | + |
| 25 | +describe('ReceiptHttp', () => { |
| 26 | + const helper = new IntegrationTestHelper(); |
| 27 | + let receiptRepository: ReceiptRepository; |
| 28 | + |
| 29 | + before(() => { |
| 30 | + return helper.start().then(() => { |
| 31 | + receiptRepository = helper.repositoryFactory.createReceiptRepository(); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('searchReceipt with streamer and recipient type type', () => { |
| 36 | + async function searchByRecipientType(receiptTypes: ReceiptType[], empty: boolean) { |
| 37 | + const streamer = ReceiptPaginationStreamer.transactionStatements(receiptRepository); |
| 38 | + |
| 39 | + const infos = await streamer |
| 40 | + .search({ pageSize: 20, height: UInt64.fromUint(1), receiptTypes: receiptTypes }) |
| 41 | + .pipe(toArray()) |
| 42 | + .toPromise(); |
| 43 | + |
| 44 | + infos.forEach((s) => { |
| 45 | + s.receipts.forEach((r) => { |
| 46 | + expect(receiptTypes.indexOf(r.type)).to.not.eq(-1); |
| 47 | + }); |
| 48 | + }); |
| 49 | + if (empty) { |
| 50 | + expect(infos.length).to.be.eq(0); |
| 51 | + } else { |
| 52 | + expect(infos.length).to.not.eq(0); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + it('should return receipt info Harvest_Fee', async () => { |
| 57 | + await searchByRecipientType([ReceiptType.Harvest_Fee], false); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should return receipt info Namespace_Rental_Fee', async () => { |
| 61 | + await searchByRecipientType([ReceiptType.Namespace_Rental_Fee], false); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should return receipt info Harvest_Fee and Namespace_Rental_Fee', async () => { |
| 65 | + await searchByRecipientType([ReceiptType.Harvest_Fee, ReceiptType.Namespace_Rental_Fee], false); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should return receipt info LockHash_Completed and Namespace_Rental_Fee', async () => { |
| 69 | + await searchByRecipientType([ReceiptType.LockHash_Completed, ReceiptType.Namespace_Rental_Fee], false); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should return receipt info LockHash_Completed', async () => { |
| 73 | + await searchByRecipientType([ReceiptType.LockHash_Completed], true); |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments