add advanced scenario-tests for coop-assets (#123)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/123 Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
@@ -20,6 +20,15 @@ components:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
membership.uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
nullable: false
|
||||
membership.memberNumber:
|
||||
type: string
|
||||
minLength: 9
|
||||
maxLength: 9
|
||||
pattern: 'M-[0-9]{7}'
|
||||
transactionType:
|
||||
$ref: '#/components/schemas/HsOfficeCoopAssetsTransactionType'
|
||||
assetValue:
|
||||
@@ -32,20 +41,36 @@ components:
|
||||
type: string
|
||||
comment:
|
||||
type: string
|
||||
adoptionAssetTx:
|
||||
# a TRANSFER tx must refer to the related ADOPTION tx
|
||||
$ref: '#/components/schemas/HsOfficeRelatedCoopAssetsTransaction'
|
||||
transferAssetTx:
|
||||
# an ADOPTION tx must refer to the related TRANSFER tx
|
||||
$ref: '#/components/schemas/HsOfficeRelatedCoopAssetsTransaction'
|
||||
revertedAssetTx:
|
||||
$ref: '#/components/schemas/HsOfficeReferencedCoopAssetsTransaction'
|
||||
# a REVERSAL tx must refer to the related tx, which can be of any type but REVERSAL
|
||||
$ref: '#/components/schemas/HsOfficeRelatedCoopAssetsTransaction'
|
||||
reversalAssetTx:
|
||||
$ref: '#/components/schemas/HsOfficeReferencedCoopAssetsTransaction'
|
||||
# a reverted tx, which can be any but REVERSAL, must refer to the related REVERSAL tx
|
||||
$ref: '#/components/schemas/HsOfficeRelatedCoopAssetsTransaction'
|
||||
|
||||
HsOfficeReferencedCoopAssetsTransaction:
|
||||
HsOfficeRelatedCoopAssetsTransaction:
|
||||
description:
|
||||
Similar to `HsOfficeCoopAssetsTransaction` but without the self-referencing properties
|
||||
(`revertedAssetTx` and `reversalAssetTx`), to avoid recursive JSON.
|
||||
Similar to `HsOfficeCoopAssetsTransaction` but just the UUID of the related property, to avoid recursive JSON.
|
||||
type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
membership.uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
nullable: false
|
||||
membership.memberNumber:
|
||||
type: string
|
||||
minLength: 9
|
||||
maxLength: 9
|
||||
pattern: 'M-[0-9]{7}'
|
||||
transactionType:
|
||||
$ref: '#/components/schemas/HsOfficeCoopAssetsTransactionType'
|
||||
assetValue:
|
||||
@@ -58,6 +83,22 @@ components:
|
||||
type: string
|
||||
comment:
|
||||
type: string
|
||||
adoptionAssetTx.uuid:
|
||||
description: a TRANSFER tx must refer to the related ADOPTION tx
|
||||
type: string
|
||||
format: uuid
|
||||
transferAssetTx.uuid:
|
||||
description: an ADOPTION tx must refer to the related TRANSFER tx
|
||||
type: string
|
||||
format: uuid
|
||||
revertedAssetTx.uuid:
|
||||
description: a REVERSAL tx must refer to the related tx, which can be of any type but REVERSAL
|
||||
type: string
|
||||
format: uuid
|
||||
reversalAssetTx.uuid:
|
||||
description: a reverted tx, which can be any but REVERSAL, must refer to the related REVERSAL tx
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
HsOfficeCoopAssetsTransactionInsert:
|
||||
type: object
|
||||
@@ -83,6 +124,14 @@ components:
|
||||
revertedAssetTx.uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
adoptingMembership.uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
adoptingMembership.memberNumber:
|
||||
type: string
|
||||
minLength: 9
|
||||
maxLength: 9
|
||||
pattern: 'M-[0-9]{7}'
|
||||
required:
|
||||
- membership.uuid
|
||||
- transactionType
|
||||
|
@@ -16,6 +16,10 @@ components:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
membership.uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
nullable: false
|
||||
transactionType:
|
||||
$ref: '#/components/schemas/HsOfficeCoopSharesTransactionType'
|
||||
shareCount:
|
||||
@@ -41,6 +45,10 @@ components:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
membership.uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
nullable: false
|
||||
transactionType:
|
||||
$ref: '#/components/schemas/HsOfficeCoopSharesTransactionType'
|
||||
shareCount:
|
||||
|
@@ -25,6 +25,7 @@ create table if not exists hs_office.coopassettx
|
||||
assetValue numeric(12,2) not null, -- https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_money
|
||||
reference varchar(48) not null,
|
||||
revertedAssetTxUuid uuid unique REFERENCES hs_office.coopassettx(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||
assetAdoptionTxUuid uuid unique REFERENCES hs_office.coopassettx(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||
comment varchar(512)
|
||||
);
|
||||
--//
|
||||
@@ -35,9 +36,20 @@ create table if not exists hs_office.coopassettx
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
alter table hs_office.coopassettx
|
||||
add constraint reverse_entry_missing
|
||||
check ( transactionType = 'REVERSAL' and revertedAssetTxUuid is not null
|
||||
or transactionType <> 'REVERSAL' and revertedAssetTxUuid is null);
|
||||
add constraint reversal_asset_tx_must_have_reverted_asset_tx
|
||||
check (transactionType <> 'REVERSAL' or revertedAssetTxUuid is not null);
|
||||
|
||||
alter table hs_office.coopassettx
|
||||
add constraint non_reversal_asset_tx_must_not_have_reverted_asset_tx
|
||||
check (transactionType = 'REVERSAL' or revertedAssetTxUuid is null or transactionType = 'REVERSAL');
|
||||
|
||||
alter table hs_office.coopassettx
|
||||
add constraint transfer_asset_tx_must_have_adopted_asset_tx
|
||||
check (transactionType <> 'TRANSFER' or assetAdoptionTxUuid is not null);
|
||||
|
||||
alter table hs_office.coopassettx
|
||||
add constraint non_transfer_asset_tx_must_not_have_adopted_asset_tx
|
||||
check (transactionType = 'TRANSFER' or assetAdoptionTxUuid is null);
|
||||
--//
|
||||
|
||||
-- ============================================================================
|
||||
|
@@ -15,7 +15,9 @@ create or replace procedure hs_office.coopassettx_create_test_data(
|
||||
language plpgsql as $$
|
||||
declare
|
||||
membership hs_office.membership;
|
||||
lossEntryUuid uuid;
|
||||
invalidLossTx uuid;
|
||||
transferTx uuid;
|
||||
adoptionTx uuid;
|
||||
begin
|
||||
select m.uuid
|
||||
from hs_office.membership m
|
||||
@@ -25,14 +27,18 @@ begin
|
||||
into membership;
|
||||
|
||||
raise notice 'creating test coopAssetsTransaction: %', givenPartnerNumber || givenMemberNumberSuffix;
|
||||
lossEntryUuid := uuid_generate_v4();
|
||||
invalidLossTx := uuid_generate_v4();
|
||||
transferTx := uuid_generate_v4();
|
||||
adoptionTx := uuid_generate_v4();
|
||||
insert
|
||||
into hs_office.coopassettx(uuid, membershipuuid, transactiontype, valuedate, assetvalue, reference, comment, revertedAssetTxUuid)
|
||||
into hs_office.coopassettx(uuid, membershipuuid, transactiontype, valuedate, assetvalue, reference, comment, revertedAssetTxUuid, assetAdoptionTxUuid)
|
||||
values
|
||||
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit', null),
|
||||
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal', null),
|
||||
(lossEntryUuid, membership.uuid, 'DEPOSIT', '2022-10-20', 128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some loss', null),
|
||||
(uuid_generate_v4(), membership.uuid, 'REVERSAL', '2022-10-21', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some reversal', lossEntryUuid);
|
||||
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit', null, null),
|
||||
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal', null, null),
|
||||
(invalidLossTx, membership.uuid, 'DEPOSIT', '2022-10-20', 128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some loss', null, null),
|
||||
(uuid_generate_v4(), membership.uuid, 'REVERSAL', '2022-10-21', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some reversal', invalidLossTx, null),
|
||||
(transferTx, membership.uuid, 'TRANSFER', '2023-12-31', -192.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some reversal', null, adoptionTx),
|
||||
(adoptionTx, membership.uuid, 'ADOPTION', '2023-12-31', 192.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some reversal', null, null);
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
|
Reference in New Issue
Block a user