Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

Add tests for new get_many_to_many query handler

authored by seoul.systems and committed by tangled.org 0936e617 1cbfe6e5

+212
+212
constellation/src/storage/mod.rs
··· 1683 1683 } 1684 1684 ); 1685 1685 }); 1686 + 1687 + test_each_storage!(get_m2m_empty, |storage| { 1688 + assert_eq!( 1689 + storage.get_many_to_many( 1690 + "a.com", 1691 + "a.b.c", 1692 + ".d.e", 1693 + ".f.g", 1694 + 10, 1695 + None, 1696 + &HashSet::new(), 1697 + &HashSet::new(), 1698 + )?, 1699 + PagedOrderedCollection { 1700 + items: vec![], 1701 + next: None, 1702 + } 1703 + ); 1704 + }); 1705 + 1706 + test_each_storage!(get_m2m_single, |storage| { 1707 + storage.push( 1708 + &ActionableEvent::CreateLinks { 1709 + record_id: RecordId { 1710 + did: "did:plc:asdf".into(), 1711 + collection: "app.t.c".into(), 1712 + rkey: "asdf".into(), 1713 + }, 1714 + links: vec![ 1715 + CollectedLink { 1716 + target: Link::Uri("a.com".into()), 1717 + path: ".abc.uri".into(), 1718 + }, 1719 + CollectedLink { 1720 + target: Link::Uri("b.com".into()), 1721 + path: ".def.uri".into(), 1722 + }, 1723 + CollectedLink { 1724 + target: Link::Uri("b.com".into()), 1725 + path: ".ghi.uri".into(), 1726 + }, 1727 + ], 1728 + }, 1729 + 0, 1730 + )?; 1731 + assert_eq!( 1732 + storage.get_many_to_many( 1733 + "a.com", 1734 + "app.t.c", 1735 + ".abc.uri", 1736 + ".def.uri", 1737 + 10, 1738 + None, 1739 + &HashSet::new(), 1740 + &HashSet::new(), 1741 + )?, 1742 + PagedOrderedCollection { 1743 + items: vec![( 1744 + "b.com".to_string(), 1745 + vec![RecordId { 1746 + did: "did:plc:asdf".into(), 1747 + collection: "app.t.c".into(), 1748 + rkey: "asdf".into(), 1749 + }] 1750 + )], 1751 + next: None, 1752 + } 1753 + ); 1754 + }); 1755 + 1756 + test_each_storage!(get_m2m_filters, |storage| { 1757 + storage.push( 1758 + &ActionableEvent::CreateLinks { 1759 + record_id: RecordId { 1760 + did: "did:plc:asdf".into(), 1761 + collection: "app.t.c".into(), 1762 + rkey: "asdf".into(), 1763 + }, 1764 + links: vec![ 1765 + CollectedLink { 1766 + target: Link::Uri("a.com".into()), 1767 + path: ".abc.uri".into(), 1768 + }, 1769 + CollectedLink { 1770 + target: Link::Uri("b.com".into()), 1771 + path: ".def.uri".into(), 1772 + }, 1773 + ], 1774 + }, 1775 + 0, 1776 + )?; 1777 + storage.push( 1778 + &ActionableEvent::CreateLinks { 1779 + record_id: RecordId { 1780 + did: "did:plc:asdf".into(), 1781 + collection: "app.t.c".into(), 1782 + rkey: "asdf2".into(), 1783 + }, 1784 + links: vec![ 1785 + CollectedLink { 1786 + target: Link::Uri("a.com".into()), 1787 + path: ".abc.uri".into(), 1788 + }, 1789 + CollectedLink { 1790 + target: Link::Uri("b.com".into()), 1791 + path: ".def.uri".into(), 1792 + }, 1793 + ], 1794 + }, 1795 + 1, 1796 + )?; 1797 + storage.push( 1798 + &ActionableEvent::CreateLinks { 1799 + record_id: RecordId { 1800 + did: "did:plc:fdsa".into(), 1801 + collection: "app.t.c".into(), 1802 + rkey: "fdsa".into(), 1803 + }, 1804 + links: vec![ 1805 + CollectedLink { 1806 + target: Link::Uri("a.com".into()), 1807 + path: ".abc.uri".into(), 1808 + }, 1809 + CollectedLink { 1810 + target: Link::Uri("c.com".into()), 1811 + path: ".def.uri".into(), 1812 + }, 1813 + ], 1814 + }, 1815 + 2, 1816 + )?; 1817 + storage.push( 1818 + &ActionableEvent::CreateLinks { 1819 + record_id: RecordId { 1820 + did: "did:plc:fdsa".into(), 1821 + collection: "app.t.c".into(), 1822 + rkey: "fdsa2".into(), 1823 + }, 1824 + links: vec![ 1825 + CollectedLink { 1826 + target: Link::Uri("a.com".into()), 1827 + path: ".abc.uri".into(), 1828 + }, 1829 + CollectedLink { 1830 + target: Link::Uri("c.com".into()), 1831 + path: ".def.uri".into(), 1832 + }, 1833 + ], 1834 + }, 1835 + 3, 1836 + )?; 1837 + 1838 + // Test without filters - should get all records grouped by secondary target 1839 + let result = storage.get_many_to_many( 1840 + "a.com", 1841 + "app.t.c", 1842 + ".abc.uri", 1843 + ".def.uri", 1844 + 10, 1845 + None, 1846 + &HashSet::new(), 1847 + &HashSet::new(), 1848 + )?; 1849 + assert_eq!(result.items.len(), 2); 1850 + assert_eq!(result.next, None); 1851 + // Find b.com group 1852 + let (b_target, b_records) = result.items.iter().find(|(target, _)| target == "b.com").unwrap(); 1853 + assert_eq!(b_target, "b.com"); 1854 + assert_eq!(b_records.len(), 2); 1855 + assert!(b_records.iter().any(|r| r.did.0 == "did:plc:asdf" && r.rkey == "asdf")); 1856 + assert!(b_records.iter().any(|r| r.did.0 == "did:plc:asdf" && r.rkey == "asdf2")); 1857 + // Find c.com group 1858 + let (c_target, c_records) = result.items.iter().find(|(target, _)| target == "c.com").unwrap(); 1859 + assert_eq!(c_target, "c.com"); 1860 + assert_eq!(c_records.len(), 2); 1861 + assert!(c_records.iter().any(|r| r.did.0 == "did:plc:fdsa" && r.rkey == "fdsa")); 1862 + assert!(c_records.iter().any(|r| r.did.0 == "did:plc:fdsa" && r.rkey == "fdsa2")); 1863 + 1864 + // Test with DID filter - should only get records from did:plc:fdsa 1865 + let result = storage.get_many_to_many( 1866 + "a.com", 1867 + "app.t.c", 1868 + ".abc.uri", 1869 + ".def.uri", 1870 + 10, 1871 + None, 1872 + &HashSet::from_iter([Did("did:plc:fdsa".to_string())]), 1873 + &HashSet::new(), 1874 + )?; 1875 + assert_eq!(result.items.len(), 1); 1876 + let (target, records) = &result.items[0]; 1877 + assert_eq!(target, "c.com"); 1878 + assert_eq!(records.len(), 2); 1879 + assert!(records.iter().all(|r| r.did.0 == "did:plc:fdsa")); 1880 + 1881 + // Test with target filter - should only get records linking to b.com 1882 + let result = storage.get_many_to_many( 1883 + "a.com", 1884 + "app.t.c", 1885 + ".abc.uri", 1886 + ".def.uri", 1887 + 10, 1888 + None, 1889 + &HashSet::new(), 1890 + &HashSet::from_iter(["b.com".to_string()]), 1891 + )?; 1892 + assert_eq!(result.items.len(), 1); 1893 + let (target, records) = &result.items[0]; 1894 + assert_eq!(target, "b.com"); 1895 + assert_eq!(records.len(), 2); 1896 + assert!(records.iter().all(|r| r.did.0 == "did:plc:asdf")); 1897 + }); 1686 1898 }