@sphereon/ssi-sdk.data-store 0.18.2-next.9 → 0.18.2-next.92

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.
Files changed (55) hide show
  1. package/dist/contact/AbstractContactStore.d.ts +11 -1
  2. package/dist/contact/AbstractContactStore.d.ts.map +1 -1
  3. package/dist/contact/AbstractContactStore.js.map +1 -1
  4. package/dist/contact/ContactStore.d.ts +27 -15
  5. package/dist/contact/ContactStore.d.ts.map +1 -1
  6. package/dist/contact/ContactStore.js +201 -32
  7. package/dist/contact/ContactStore.js.map +1 -1
  8. package/dist/entities/contact/ElectronicAddressEntity.d.ts +1 -0
  9. package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -1
  10. package/dist/entities/contact/ElectronicAddressEntity.js +4 -0
  11. package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -1
  12. package/dist/entities/contact/IdentityEntity.d.ts +1 -1
  13. package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
  14. package/dist/entities/contact/PartyEntity.d.ts +2 -0
  15. package/dist/entities/contact/PartyEntity.d.ts.map +1 -1
  16. package/dist/entities/contact/PartyEntity.js +12 -1
  17. package/dist/entities/contact/PartyEntity.js.map +1 -1
  18. package/dist/entities/contact/PhysicalAddressEntity.d.ts +21 -0
  19. package/dist/entities/contact/PhysicalAddressEntity.d.ts.map +1 -0
  20. package/dist/entities/contact/PhysicalAddressEntity.js +126 -0
  21. package/dist/entities/contact/PhysicalAddressEntity.js.map +1 -0
  22. package/dist/index.d.ts +2 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
  27. package/dist/issuanceBranding/IssuanceBrandingStore.js +76 -60
  28. package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -1
  29. package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -1
  30. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +3 -6
  31. package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
  32. package/dist/types/contact/IAbstractContactStore.d.ts +36 -1
  33. package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -1
  34. package/dist/types/contact/contact.d.ts +27 -4
  35. package/dist/types/contact/contact.d.ts.map +1 -1
  36. package/dist/types/contact/contact.js.map +1 -1
  37. package/dist/utils/contact/MappingUtils.d.ts +4 -1
  38. package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
  39. package/dist/utils/contact/MappingUtils.js +37 -1
  40. package/dist/utils/contact/MappingUtils.js.map +1 -1
  41. package/package.json +4 -4
  42. package/src/__tests__/contact.entities.test.ts +340 -23
  43. package/src/__tests__/contact.store.test.ts +629 -10
  44. package/src/contact/AbstractContactStore.ts +38 -16
  45. package/src/contact/ContactStore.ts +278 -58
  46. package/src/entities/contact/ElectronicAddressEntity.ts +3 -0
  47. package/src/entities/contact/IdentityEntity.ts +1 -1
  48. package/src/entities/contact/PartyEntity.ts +11 -1
  49. package/src/entities/contact/PhysicalAddressEntity.ts +87 -0
  50. package/src/index.ts +3 -0
  51. package/src/issuanceBranding/IssuanceBrandingStore.ts +83 -69
  52. package/src/migrations/sqlite/1690925872693-CreateContacts.ts +3 -8
  53. package/src/types/contact/IAbstractContactStore.ts +58 -8
  54. package/src/types/contact/contact.ts +40 -4
  55. package/src/utils/contact/MappingUtils.ts +39 -0
@@ -2,22 +2,28 @@ import { DataSource } from 'typeorm'
2
2
  import { DataStoreMigrations, DataStoreContactEntities } from '../index'
3
3
  import { ContactStore } from '../contact/ContactStore'
4
4
  import {
5
- IdentityRoleEnum,
6
- PartyTypeEnum,
7
- NonPersistedParty,
8
- Party,
9
5
  CorrelationIdentifierEnum,
6
+ ElectronicAddress,
7
+ GetElectronicAddressesArgs,
8
+ GetIdentitiesArgs,
9
+ GetPartiesArgs,
10
+ GetPhysicalAddressesArgs,
11
+ GetRelationshipsArgs,
10
12
  Identity,
13
+ IdentityRoleEnum,
11
14
  NaturalPerson,
12
- NonPersistedNaturalPerson,
15
+ NonPersistedElectronicAddress,
13
16
  NonPersistedIdentity,
14
- GetIdentitiesArgs,
15
- GetPartiesArgs,
17
+ NonPersistedNaturalPerson,
18
+ NonPersistedParty,
16
19
  NonPersistedPartyRelationship,
20
+ NonPersistedPartyType,
21
+ NonPersistedPhysicalAddress,
22
+ Party,
17
23
  PartyRelationship,
18
24
  PartyType,
19
- GetRelationshipsArgs,
20
- NonPersistedPartyType,
25
+ PartyTypeEnum,
26
+ PhysicalAddress,
21
27
  } from '../types'
22
28
 
23
29
  describe('Contact store tests', (): void => {
@@ -204,7 +210,7 @@ describe('Contact store tests', (): void => {
204
210
  electronicAddresses: [
205
211
  {
206
212
  type: 'email',
207
- electronicAddress: 'sphereon@sphereon.com',
213
+ electronicAddress: 'example_electronic_address',
208
214
  },
209
215
  ],
210
216
  }
@@ -1676,6 +1682,7 @@ describe('Contact store tests', (): void => {
1676
1682
  expect(resultPartyType).toBeDefined()
1677
1683
 
1678
1684
  const includingMigrationPartyTypes: Array<PartyType> = await contactStore.getPartyTypes()
1685
+ // We are checking for 2 types here as we include the one from the migrations
1679
1686
  expect(includingMigrationPartyTypes.length).toEqual(2)
1680
1687
 
1681
1688
  await contactStore.removePartyType({ partyTypeId: savedPartyType.id })
@@ -1776,4 +1783,616 @@ describe('Contact store tests', (): void => {
1776
1783
 
1777
1784
  await expect(contactStore.addParty(party)).rejects.toThrow(`Party type ${partyType}, does not match for provided contact`)
1778
1785
  })
1786
+
1787
+ it('should get electronic address by id', async (): Promise<void> => {
1788
+ const party: NonPersistedParty = {
1789
+ uri: 'example.com',
1790
+ partyType: {
1791
+ type: PartyTypeEnum.NATURAL_PERSON,
1792
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
1793
+ name: 'example_name',
1794
+ },
1795
+ contact: {
1796
+ firstName: 'example_first_name',
1797
+ middleName: 'example_middle_name',
1798
+ lastName: 'example_last_name',
1799
+ displayName: 'example_display_name',
1800
+ },
1801
+ }
1802
+ const savedParty: Party = await contactStore.addParty(party)
1803
+ expect(savedParty).toBeDefined()
1804
+
1805
+ const electronicAddress: NonPersistedElectronicAddress = {
1806
+ type: 'email',
1807
+ electronicAddress: 'example_electronic_address',
1808
+ }
1809
+ const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
1810
+ expect(savedElectronicAddress).toBeDefined()
1811
+
1812
+ const result: ElectronicAddress = await contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
1813
+
1814
+ expect(result).toBeDefined()
1815
+ })
1816
+
1817
+ it('should throw error when getting electronic address with unknown id', async (): Promise<void> => {
1818
+ const electronicAddressId = 'unknownElectronicAddressId'
1819
+
1820
+ await expect(contactStore.getElectronicAddress({ electronicAddressId })).rejects.toThrow(
1821
+ `No electronic address found for id: ${electronicAddressId}`
1822
+ )
1823
+ })
1824
+
1825
+ it('should get all electronic addresses for contact', async (): Promise<void> => {
1826
+ const party: NonPersistedParty = {
1827
+ uri: 'example.com',
1828
+ partyType: {
1829
+ type: PartyTypeEnum.NATURAL_PERSON,
1830
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
1831
+ name: 'example_name',
1832
+ },
1833
+ contact: {
1834
+ firstName: 'example_first_name',
1835
+ middleName: 'example_middle_name',
1836
+ lastName: 'example_last_name',
1837
+ displayName: 'example_display_name',
1838
+ },
1839
+ }
1840
+ const savedParty: Party = await contactStore.addParty(party)
1841
+ expect(savedParty).toBeDefined()
1842
+
1843
+ const electronicAddress1: NonPersistedElectronicAddress = {
1844
+ type: 'email',
1845
+ electronicAddress: 'example_electronic_address1',
1846
+ }
1847
+ const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
1848
+ partyId: savedParty.id,
1849
+ electronicAddress: electronicAddress1,
1850
+ })
1851
+ expect(savedElectronicAddress1).toBeDefined()
1852
+
1853
+ const electronicAddress2: NonPersistedElectronicAddress = {
1854
+ type: 'email',
1855
+ electronicAddress: 'example_electronic_address2',
1856
+ }
1857
+ const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
1858
+ partyId: savedParty.id,
1859
+ electronicAddress: electronicAddress2,
1860
+ })
1861
+ expect(savedElectronicAddress2).toBeDefined()
1862
+
1863
+ const args: GetElectronicAddressesArgs = {
1864
+ filter: [{ partyId: savedParty.id }],
1865
+ }
1866
+
1867
+ const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses(args)
1868
+
1869
+ expect(result.length).toEqual(2)
1870
+ })
1871
+
1872
+ it('should get all electronic addresses', async (): Promise<void> => {
1873
+ const party: NonPersistedParty = {
1874
+ uri: 'example.com',
1875
+ partyType: {
1876
+ type: PartyTypeEnum.NATURAL_PERSON,
1877
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
1878
+ name: 'example_name',
1879
+ },
1880
+ contact: {
1881
+ firstName: 'example_first_name',
1882
+ middleName: 'example_middle_name',
1883
+ lastName: 'example_last_name',
1884
+ displayName: 'example_display_name',
1885
+ },
1886
+ }
1887
+ const savedParty: Party = await contactStore.addParty(party)
1888
+ expect(savedParty).toBeDefined()
1889
+
1890
+ const electronicAddress1: NonPersistedElectronicAddress = {
1891
+ type: 'email',
1892
+ electronicAddress: 'example_electronic_address1',
1893
+ }
1894
+ const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
1895
+ partyId: savedParty.id,
1896
+ electronicAddress: electronicAddress1,
1897
+ })
1898
+ expect(savedElectronicAddress1).toBeDefined()
1899
+
1900
+ const electronicAddress2: NonPersistedElectronicAddress = {
1901
+ type: 'email',
1902
+ electronicAddress: 'example_electronic_address2',
1903
+ }
1904
+ const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
1905
+ partyId: savedParty.id,
1906
+ electronicAddress: electronicAddress2,
1907
+ })
1908
+ expect(savedElectronicAddress2).toBeDefined()
1909
+
1910
+ const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses()
1911
+
1912
+ expect(result.length).toEqual(2)
1913
+ })
1914
+
1915
+ it('should get electronic addresses by filter', async (): Promise<void> => {
1916
+ const party: NonPersistedParty = {
1917
+ uri: 'example.com',
1918
+ partyType: {
1919
+ type: PartyTypeEnum.NATURAL_PERSON,
1920
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
1921
+ name: 'example_name',
1922
+ },
1923
+ contact: {
1924
+ firstName: 'example_first_name',
1925
+ middleName: 'example_middle_name',
1926
+ lastName: 'example_last_name',
1927
+ displayName: 'example_display_name',
1928
+ },
1929
+ }
1930
+ const savedParty: Party = await contactStore.addParty(party)
1931
+ expect(savedParty).toBeDefined()
1932
+
1933
+ const electronicAddress = 'example_electronic_address1'
1934
+ const electronicAddress1: NonPersistedElectronicAddress = {
1935
+ type: 'email',
1936
+ electronicAddress,
1937
+ }
1938
+ const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
1939
+ partyId: savedParty.id,
1940
+ electronicAddress: electronicAddress1,
1941
+ })
1942
+ expect(savedElectronicAddress1).toBeDefined()
1943
+
1944
+ const electronicAddress2: NonPersistedElectronicAddress = {
1945
+ type: 'email',
1946
+ electronicAddress: 'example_electronic_address2',
1947
+ }
1948
+ const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
1949
+ partyId: savedParty.id,
1950
+ electronicAddress: electronicAddress2,
1951
+ })
1952
+ expect(savedElectronicAddress2).toBeDefined()
1953
+
1954
+ const args: GetElectronicAddressesArgs = {
1955
+ filter: [{ electronicAddress }],
1956
+ }
1957
+
1958
+ const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses(args)
1959
+
1960
+ expect(result.length).toEqual(1)
1961
+ })
1962
+
1963
+ it('should add electronic address to contact', async (): Promise<void> => {
1964
+ const party: NonPersistedParty = {
1965
+ uri: 'example.com',
1966
+ partyType: {
1967
+ type: PartyTypeEnum.NATURAL_PERSON,
1968
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
1969
+ name: 'example_name',
1970
+ },
1971
+ contact: {
1972
+ firstName: 'example_first_name',
1973
+ middleName: 'example_middle_name',
1974
+ lastName: 'example_last_name',
1975
+ displayName: 'example_display_name',
1976
+ },
1977
+ }
1978
+ const savedParty: Party = await contactStore.addParty(party)
1979
+ expect(savedParty).toBeDefined()
1980
+
1981
+ const electronicAddress: NonPersistedElectronicAddress = {
1982
+ type: 'email',
1983
+ electronicAddress: 'example_electronic_address',
1984
+ }
1985
+ const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
1986
+ expect(savedElectronicAddress).toBeDefined()
1987
+
1988
+ const result: Party = await contactStore.getParty({ partyId: savedParty.id })
1989
+ expect(result.electronicAddresses.length).toEqual(1)
1990
+ })
1991
+
1992
+ it('should update electronic address by id', async (): Promise<void> => {
1993
+ const party: NonPersistedParty = {
1994
+ uri: 'example.com',
1995
+ partyType: {
1996
+ type: PartyTypeEnum.NATURAL_PERSON,
1997
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
1998
+ name: 'example_name',
1999
+ },
2000
+ contact: {
2001
+ firstName: 'example_first_name',
2002
+ middleName: 'example_middle_name',
2003
+ lastName: 'example_last_name',
2004
+ displayName: 'example_display_name',
2005
+ },
2006
+ }
2007
+ const savedParty: Party = await contactStore.addParty(party)
2008
+ expect(savedParty).toBeDefined()
2009
+
2010
+ const electronicAddress: NonPersistedElectronicAddress = {
2011
+ type: 'email',
2012
+ electronicAddress: 'example_electronic_address',
2013
+ }
2014
+ const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
2015
+ const newElectronicAddress = 'new_example_electronic_address'
2016
+ savedElectronicAddress.electronicAddress = newElectronicAddress
2017
+
2018
+ await contactStore.updateElectronicAddress({ electronicAddress: savedElectronicAddress })
2019
+ const result: ElectronicAddress = await contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
2020
+
2021
+ expect(result).toBeDefined()
2022
+ expect(result.electronicAddress).toEqual(newElectronicAddress)
2023
+ })
2024
+
2025
+ it('should remove electronic address', async (): Promise<void> => {
2026
+ const party: NonPersistedParty = {
2027
+ uri: 'example.com',
2028
+ partyType: {
2029
+ type: PartyTypeEnum.NATURAL_PERSON,
2030
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2031
+ name: 'example_name',
2032
+ },
2033
+ contact: {
2034
+ firstName: 'example_first_name',
2035
+ middleName: 'example_middle_name',
2036
+ lastName: 'example_last_name',
2037
+ displayName: 'example_display_name',
2038
+ },
2039
+ }
2040
+ const savedParty: Party = await contactStore.addParty(party)
2041
+ expect(savedParty).toBeDefined()
2042
+
2043
+ const electronicAddress: NonPersistedElectronicAddress = {
2044
+ type: 'email',
2045
+ electronicAddress: 'example_electronic_address',
2046
+ }
2047
+ const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
2048
+ expect(savedElectronicAddress).toBeDefined()
2049
+
2050
+ await contactStore.removeElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
2051
+
2052
+ await expect(contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })).rejects.toThrow(
2053
+ `No electronic address found for id: ${savedElectronicAddress.id}`
2054
+ )
2055
+ })
2056
+
2057
+ it('should throw error when removing electronic address with unknown id', async (): Promise<void> => {
2058
+ const electronicAddressId = 'unknownElectronicAddressId'
2059
+
2060
+ await expect(contactStore.removeElectronicAddress({ electronicAddressId })).rejects.toThrow(
2061
+ `No electronic address found for id: ${electronicAddressId}`
2062
+ )
2063
+ })
2064
+
2065
+ it('should get physical address by id', async (): Promise<void> => {
2066
+ const party: NonPersistedParty = {
2067
+ uri: 'example.com',
2068
+ partyType: {
2069
+ type: PartyTypeEnum.NATURAL_PERSON,
2070
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2071
+ name: 'example_name',
2072
+ },
2073
+ contact: {
2074
+ firstName: 'example_first_name',
2075
+ middleName: 'example_middle_name',
2076
+ lastName: 'example_last_name',
2077
+ displayName: 'example_display_name',
2078
+ },
2079
+ }
2080
+ const savedParty: Party = await contactStore.addParty(party)
2081
+ expect(savedParty).toBeDefined()
2082
+
2083
+ const physicalAddress: NonPersistedPhysicalAddress = {
2084
+ type: 'home',
2085
+ streetName: 'example_street_name',
2086
+ streetNumber: 'example_street_number',
2087
+ buildingName: 'example_building_name',
2088
+ postalCode: 'example_postal_code',
2089
+ cityName: 'example_city_name',
2090
+ provinceName: 'example_province_name',
2091
+ countryCode: 'example_country_code',
2092
+ }
2093
+ const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
2094
+ expect(savedPhysicalAddress).toBeDefined()
2095
+
2096
+ const result: PhysicalAddress = await contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
2097
+
2098
+ expect(result).toBeDefined()
2099
+ })
2100
+
2101
+ it('should throw error when getting physical address with unknown id', async (): Promise<void> => {
2102
+ const physicalAddressId = 'unknownPhysicalAddressId'
2103
+
2104
+ await expect(contactStore.getPhysicalAddress({ physicalAddressId })).rejects.toThrow(`No physical address found for id: ${physicalAddressId}`)
2105
+ })
2106
+
2107
+ it('should get all physical addresses for contact', async (): Promise<void> => {
2108
+ const party: NonPersistedParty = {
2109
+ uri: 'example.com',
2110
+ partyType: {
2111
+ type: PartyTypeEnum.NATURAL_PERSON,
2112
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2113
+ name: 'example_name',
2114
+ },
2115
+ contact: {
2116
+ firstName: 'example_first_name',
2117
+ middleName: 'example_middle_name',
2118
+ lastName: 'example_last_name',
2119
+ displayName: 'example_display_name',
2120
+ },
2121
+ }
2122
+ const savedParty: Party = await contactStore.addParty(party)
2123
+ expect(savedParty).toBeDefined()
2124
+
2125
+ const physicalAddress1: NonPersistedPhysicalAddress = {
2126
+ type: 'home',
2127
+ streetName: 'example_street_name',
2128
+ streetNumber: 'example_street_number',
2129
+ buildingName: 'example_building_name',
2130
+ postalCode: 'example_postal_code',
2131
+ cityName: 'example_city_name',
2132
+ provinceName: 'example_province_name',
2133
+ countryCode: 'example_country_code',
2134
+ }
2135
+ const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
2136
+ partyId: savedParty.id,
2137
+ physicalAddress: physicalAddress1,
2138
+ })
2139
+ expect(savedPhysicalAddress1).toBeDefined()
2140
+
2141
+ const physicalAddress2: NonPersistedPhysicalAddress = {
2142
+ type: 'home',
2143
+ streetName: 'example_street_name',
2144
+ streetNumber: 'example_street_number',
2145
+ buildingName: 'example_building_name',
2146
+ postalCode: 'example_postal_code',
2147
+ cityName: 'example_city_name',
2148
+ provinceName: 'example_province_name',
2149
+ countryCode: 'example_country_code',
2150
+ }
2151
+ const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
2152
+ partyId: savedParty.id,
2153
+ physicalAddress: physicalAddress2,
2154
+ })
2155
+ expect(savedPhysicalAddress2).toBeDefined()
2156
+
2157
+ const args: GetPhysicalAddressesArgs = {
2158
+ filter: [{ partyId: savedParty.id }],
2159
+ }
2160
+
2161
+ const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses(args)
2162
+
2163
+ expect(result.length).toEqual(2)
2164
+ })
2165
+
2166
+ it('should get all electronic addresses', async (): Promise<void> => {
2167
+ const party: NonPersistedParty = {
2168
+ uri: 'example.com',
2169
+ partyType: {
2170
+ type: PartyTypeEnum.NATURAL_PERSON,
2171
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2172
+ name: 'example_name',
2173
+ },
2174
+ contact: {
2175
+ firstName: 'example_first_name',
2176
+ middleName: 'example_middle_name',
2177
+ lastName: 'example_last_name',
2178
+ displayName: 'example_display_name',
2179
+ },
2180
+ }
2181
+ const savedParty: Party = await contactStore.addParty(party)
2182
+ expect(savedParty).toBeDefined()
2183
+
2184
+ const physicalAddress1: NonPersistedPhysicalAddress = {
2185
+ type: 'home',
2186
+ streetName: 'example_street_name',
2187
+ streetNumber: 'example_street_number',
2188
+ buildingName: 'example_building_name',
2189
+ postalCode: 'example_postal_code',
2190
+ cityName: 'example_city_name',
2191
+ provinceName: 'example_province_name',
2192
+ countryCode: 'example_country_code',
2193
+ }
2194
+ const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
2195
+ partyId: savedParty.id,
2196
+ physicalAddress: physicalAddress1,
2197
+ })
2198
+ expect(savedPhysicalAddress1).toBeDefined()
2199
+
2200
+ const physicalAddress2: NonPersistedPhysicalAddress = {
2201
+ type: 'home',
2202
+ streetName: 'example_street_name',
2203
+ streetNumber: 'example_street_number',
2204
+ buildingName: 'example_building_name',
2205
+ postalCode: 'example_postal_code',
2206
+ cityName: 'example_city_name',
2207
+ provinceName: 'example_province_name',
2208
+ countryCode: 'example_country_code',
2209
+ }
2210
+ const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
2211
+ partyId: savedParty.id,
2212
+ physicalAddress: physicalAddress2,
2213
+ })
2214
+ expect(savedPhysicalAddress2).toBeDefined()
2215
+
2216
+ const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses()
2217
+
2218
+ expect(result.length).toEqual(2)
2219
+ })
2220
+
2221
+ it('should get electronic addresses by filter', async (): Promise<void> => {
2222
+ const party: NonPersistedParty = {
2223
+ uri: 'example.com',
2224
+ partyType: {
2225
+ type: PartyTypeEnum.NATURAL_PERSON,
2226
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2227
+ name: 'example_name',
2228
+ },
2229
+ contact: {
2230
+ firstName: 'example_first_name',
2231
+ middleName: 'example_middle_name',
2232
+ lastName: 'example_last_name',
2233
+ displayName: 'example_display_name',
2234
+ },
2235
+ }
2236
+ const savedParty: Party = await contactStore.addParty(party)
2237
+ expect(savedParty).toBeDefined()
2238
+
2239
+ const streetName = 'example_electronic_address1'
2240
+ const physicalAddress1: NonPersistedPhysicalAddress = {
2241
+ type: 'home',
2242
+ streetName,
2243
+ streetNumber: 'example_street_number1',
2244
+ buildingName: 'example_building_name1',
2245
+ postalCode: 'example_postal_code1',
2246
+ cityName: 'example_city_name1',
2247
+ provinceName: 'example_province_name1',
2248
+ countryCode: 'example_country_code1',
2249
+ }
2250
+ const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
2251
+ partyId: savedParty.id,
2252
+ physicalAddress: physicalAddress1,
2253
+ })
2254
+ expect(savedPhysicalAddress1).toBeDefined()
2255
+
2256
+ const physicalAddress2: NonPersistedPhysicalAddress = {
2257
+ type: 'home',
2258
+ streetName: 'example_street_name2',
2259
+ streetNumber: 'example_street_number2',
2260
+ buildingName: 'example_building_name2',
2261
+ postalCode: 'example_postal_code2',
2262
+ cityName: 'example_city_name2',
2263
+ provinceName: 'example_province_name2',
2264
+ countryCode: 'example_country_code2',
2265
+ }
2266
+ const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
2267
+ partyId: savedParty.id,
2268
+ physicalAddress: physicalAddress2,
2269
+ })
2270
+ expect(savedPhysicalAddress2).toBeDefined()
2271
+
2272
+ const args: GetPhysicalAddressesArgs = {
2273
+ filter: [{ streetName }],
2274
+ }
2275
+
2276
+ const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses(args)
2277
+
2278
+ expect(result.length).toEqual(1)
2279
+ })
2280
+
2281
+ it('should add physical address to contact', async (): Promise<void> => {
2282
+ const party: NonPersistedParty = {
2283
+ uri: 'example.com',
2284
+ partyType: {
2285
+ type: PartyTypeEnum.NATURAL_PERSON,
2286
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2287
+ name: 'example_name',
2288
+ },
2289
+ contact: {
2290
+ firstName: 'example_first_name',
2291
+ middleName: 'example_middle_name',
2292
+ lastName: 'example_last_name',
2293
+ displayName: 'example_display_name',
2294
+ },
2295
+ }
2296
+ const savedParty: Party = await contactStore.addParty(party)
2297
+ expect(savedParty).toBeDefined()
2298
+
2299
+ const physicalAddress: NonPersistedPhysicalAddress = {
2300
+ type: 'home',
2301
+ streetName: 'example_street_name',
2302
+ streetNumber: 'example_street_number',
2303
+ buildingName: 'example_building_name',
2304
+ postalCode: 'example_postal_code',
2305
+ cityName: 'example_city_name',
2306
+ provinceName: 'example_province_name',
2307
+ countryCode: 'example_country_code',
2308
+ }
2309
+ const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
2310
+ expect(savedPhysicalAddress).toBeDefined()
2311
+
2312
+ const result: Party = await contactStore.getParty({ partyId: savedParty.id })
2313
+ expect(result.physicalAddresses.length).toEqual(1)
2314
+ })
2315
+
2316
+ it('should update physical address by id', async (): Promise<void> => {
2317
+ const party: NonPersistedParty = {
2318
+ uri: 'example.com',
2319
+ partyType: {
2320
+ type: PartyTypeEnum.NATURAL_PERSON,
2321
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2322
+ name: 'example_name',
2323
+ },
2324
+ contact: {
2325
+ firstName: 'example_first_name',
2326
+ middleName: 'example_middle_name',
2327
+ lastName: 'example_last_name',
2328
+ displayName: 'example_display_name',
2329
+ },
2330
+ }
2331
+ const savedParty: Party = await contactStore.addParty(party)
2332
+ expect(savedParty).toBeDefined()
2333
+
2334
+ const physicalAddress: NonPersistedPhysicalAddress = {
2335
+ type: 'home',
2336
+ streetName: 'example_street_name',
2337
+ streetNumber: 'example_street_number',
2338
+ buildingName: 'example_building_name',
2339
+ postalCode: 'example_postal_code',
2340
+ cityName: 'example_city_name',
2341
+ provinceName: 'example_province_name',
2342
+ countryCode: 'example_country_code',
2343
+ }
2344
+ const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
2345
+ const newStreetName = 'new_example_street_name'
2346
+ savedPhysicalAddress.streetName = newStreetName
2347
+
2348
+ await contactStore.updatePhysicalAddress({ physicalAddress: savedPhysicalAddress })
2349
+ const result: PhysicalAddress = await contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
2350
+
2351
+ expect(result).toBeDefined()
2352
+ expect(result.streetName).toEqual(newStreetName)
2353
+ })
2354
+
2355
+ it('should remove physical address', async (): Promise<void> => {
2356
+ const party: NonPersistedParty = {
2357
+ uri: 'example.com',
2358
+ partyType: {
2359
+ type: PartyTypeEnum.NATURAL_PERSON,
2360
+ tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
2361
+ name: 'example_name',
2362
+ },
2363
+ contact: {
2364
+ firstName: 'example_first_name',
2365
+ middleName: 'example_middle_name',
2366
+ lastName: 'example_last_name',
2367
+ displayName: 'example_display_name',
2368
+ },
2369
+ }
2370
+ const savedParty: Party = await contactStore.addParty(party)
2371
+ expect(savedParty).toBeDefined()
2372
+
2373
+ const physicalAddress: NonPersistedPhysicalAddress = {
2374
+ type: 'home',
2375
+ streetName: 'example_street_name',
2376
+ streetNumber: 'example_street_number',
2377
+ buildingName: 'example_building_name',
2378
+ postalCode: 'example_postal_code',
2379
+ cityName: 'example_city_name',
2380
+ provinceName: 'example_province_name',
2381
+ countryCode: 'example_country_code',
2382
+ }
2383
+ const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
2384
+ expect(savedPhysicalAddress).toBeDefined()
2385
+
2386
+ await contactStore.removePhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
2387
+
2388
+ await expect(contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })).rejects.toThrow(
2389
+ `No physical address found for id: ${savedPhysicalAddress.id}`
2390
+ )
2391
+ })
2392
+
2393
+ it('should throw error when removing physical address with unknown id', async (): Promise<void> => {
2394
+ const physicalAddressId = 'unknownPhysicalAddressId'
2395
+
2396
+ await expect(contactStore.removePhysicalAddress({ physicalAddressId })).rejects.toThrow(`No physical address found for id: ${physicalAddressId}`)
2397
+ })
1779
2398
  })