Skip to content

Commit

Permalink
contacts: fix agent unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajpp committed Sep 16, 2024
1 parent 9b5795f commit 043cca9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 66 deletions.
39 changes: 20 additions & 19 deletions desk/app/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
+$ card card:agent:gall
+$ state-1 [%1 rof=$@(~ profile-1) =book =peers]
--
%- %^ agent:neg
notify=|
[~.contacts^%1 ~ ~]
[~.contacts^[~.contacts^%1 ~ ~] ~ ~]
:: %- %^ agent:neg
:: notify=|
:: [~.contacts^%1 ~ ~]
:: [~.contacts^[~.contacts^%1 ~ ~] ~ ~]
%- agent:dbug
%+ verb &
%+ verb |
^- agent:gall
=| state-1
=* state -
Expand Down Expand Up @@ -94,8 +94,8 @@
::
:: |pub: publication mgmt
::
:: - /news: local updates to our profile and rolodex
:: - /contact: updates to our profile
:: - /v1/news: local updates to our profile and rolodex
:: - /v1/contact: updates to our profile
::
:: as these publications are trivial, |pub does *not*
:: make use of the +abet pattern. the only behavior of note
Expand All @@ -105,6 +105,11 @@
:: /epic protocol versions are even more trivial,
:: published ad-hoc, elsewhere.
::
:: Facts are always send in the following order:
:: 1. (legacy) /news
:: 2. /v1/news
:: 3. /v1/contact
::
++ pub
=> |%
:: if this proves to be too slow, the set of paths
Expand Down Expand Up @@ -147,14 +152,12 @@
++ p-anon ?.(?=([@ ^] rof) cor (p-send-self ~))
::
++ p-self
|= e=(map @tas value-1)
|= con=(map @tas value-1)
=/ old=contact-1
?.(?=([@ ^] rof) *contact-1 con.rof)
=/ new=contact-1
(do-edit-1 old e)
?: =(old new)
?: =(old con)
cor
(p-send-self new)
(p-send-self con)
:: +p-page: create new contact page
::
++ p-page
Expand All @@ -171,11 +174,9 @@
(~(got by book) kip)
=/ old=contact-1
q.page
=/ new=contact-1
(do-edit-1 q.page mod)
?: =(old new)
?: =(old mod)
cor
(p-send-edit kip p.page new)
(p-send-edit kip p.page mod)
:: +p-wipe: delete a contact page
::
++ p-wipe
Expand Down Expand Up @@ -205,11 +206,11 @@
=/ p=profile-1 [?~(rof now.bowl (mono wen.rof now.bowl)) con]
=. rof p
::
=. cor
(give (fact subs [%full p]))
=. cor
(p-news-0 our.bowl (to-contact-0 con))
(p-news [%self con])
=. cor
(p-news [%self con])
(give (fact subs [%full p]))
:: +p-send-page: publish new contact page
::
++ p-send-page
Expand Down
94 changes: 47 additions & 47 deletions desk/tests/app/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
:~ nickname+'Zod'
bio+'The first of the galaxies'
==
:: foreign subscriber to /contact
:: foreign subscriber to /v1/contact
::
;< ~ b (set-src ~sun)
;< caz=(list card) b (do-watch /contact)
;< caz=(list card) b (do-watch /v1/contact)
:: local subscriber to /news
::
;< ~ b (set-src our.bowl)
Expand All @@ -58,10 +58,9 @@
[%full (mono now.bowl now.bowl) ~]
;< caz=(list card) b (do-poke %contact-action !>([%anon ~]))
%+ ex-cards caz
:~ (ex-fact ~[/contact] %contact-update !>(upd-0))
(ex-fact ~ %contact-update-1 !>(upd-1))
(ex-fact ~[/news] %contact-news !>([our.bowl ~]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%self ~]))
:~ (ex-fact ~[/news] contact-news+!>([our.bowl ~]))
(ex-fact ~[/v1/news] contact-news-1+!>([%self ~]))
(ex-fact ~[/v1/contact] contact-update-1+!>(upd-1))
==
:: +test-poke-0-edit: v0 edit the profile
::
Expand Down Expand Up @@ -91,24 +90,27 @@
:~ nickname+'Zod'
bio+'The first of the galaxies'
==
:: foreign subscriber to /contact
:: foreign subscriber to /v1/contact
::
;< ~ b (set-src ~sun)
;< caz=(list card) b (do-watch /contact)
;< caz=(list card) b (do-watch /v1/contact)
:: local subscriber to /news
::
;< ~ b (set-src our.bowl)
;< caz=(list card) b (do-watch /news)
:: local subscriber to /v1/news
::
;< ~ b (set-src our.bowl)
;< caz=(list card) b (do-watch /v1/news)
::
;< ~ b (set-src our.bowl)
:: action-0 profile %edit
::
;< caz=(list card) b (do-poke %contact-action !>([%edit edit-0]))
%+ ex-cards caz
:~ (ex-fact ~[/contact] %contact-update !>(upd-0))
(ex-fact ~ %contact-update-1 !>(upd-1))
(ex-fact ~[/news] %contact-news !>([our.bowl con-0]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%self con-1]))
:~ (ex-fact ~[/news] contact-news+!>([our.bowl con-0]))
(ex-fact ~[/v1/news] contact-news-1+!>([%self con-1]))
(ex-fact ~[/v1/contact] contact-update-1+!>([%full now.bowl con-1]))
==
:: +test-poke-meet-0: v0 meet a peer
::
Expand Down Expand Up @@ -177,10 +179,9 @@
:: news is published on /news, /v1/news
::
;< ~ b %+ ex-cards caz
:~ (ex-fact ~ %contact-update !>([%full (add now.bowl tick) ~]))
(ex-fact ~[/v1/contact] %contact-update-1 !>([%full (add now.bowl tick) ~]))
(ex-fact ~[/news] %contact-news !>([our.bowl ~]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%self ~]))
:~ (ex-fact ~[/news] contact-news+!>([our.bowl ~]))
(ex-fact ~[/v1/news] contact-news-1+!>([%self ~]))
(ex-fact ~[/v1/contact] contact-update-1+!>([%full (add now.bowl tick) ~]))
==
:: v0 profile is empty
::
Expand Down Expand Up @@ -234,10 +235,9 @@
::
;< caz=(list card) b (do-poke %contact-action-1 !>([%self con-1]))
%+ ex-cards caz
:~ (ex-fact ~ %contact-update !>(upd-0))
(ex-fact ~[/v1/contact] %contact-update-1 !>(upd-1))
(ex-fact ~[/news] %contact-news !>([our.bowl con-0]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%self con-1]))
:~ (ex-fact ~[/news] contact-news+!>([our.bowl con-0]))
(ex-fact ~[/v1/news] contact-news-1+!>([%self con-1]))
(ex-fact ~[/v1/contact] contact-update-1+!>(upd-1))
==
:: +test-poke-page: create new contact page
::
Expand Down Expand Up @@ -315,7 +315,7 @@
:: news is published on /v1/news
::
;< ~ b %+ ex-cards caz
:~ (ex-fact ~[/v1/news] %contact-news-1 !>(news-1))
:~ (ex-fact ~[/v1/news] contact-news-1+!>(news-1))
==
:: peek page in the book: new contact page is found
::
Expand Down Expand Up @@ -351,8 +351,8 @@
(do-agent /contact [~sun %contacts] %fact %contact-update-1 !>([%full now.bowl con-sun]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%peer ~sun con-sun]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] contact-news-1+!>([%peer ~sun con-sun]))
==
:: ~sun appears in peers
::
Expand Down Expand Up @@ -391,9 +391,9 @@
;< ~ b
%+ ex-cards caz
:~ (ex-task /contact [~sun %contacts] %watch /v1/contact)
(ex-fact ~[/news] %contact-news !>([~sun ~]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%peer ~sun ~]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%page ~sun `page:c`[~ ~]]))
(ex-fact ~[/news] contact-news+!>([~sun ~]))
(ex-fact ~[/v1/news] contact-news-1+!>([%peer ~sun ~]))
(ex-fact ~[/v1/news] contact-news-1+!>([%page ~sun `page:c`[~ ~]]))
==
:: ~sun appears in peers
::
Expand All @@ -410,9 +410,9 @@
(do-agent /contact [~sun %contacts] %fact %contact-update-1 !>([%full now.bowl con-sun]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%page ~sun con-sun ~]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%peer ~sun con-sun]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] contact-news-1+!>([%page ~sun con-sun ~]))
(ex-fact ~[/v1/news] contact-news-1+!>([%peer ~sun con-sun]))
==
:: ~sun contact page is edited
::
Expand Down Expand Up @@ -464,8 +464,8 @@
(do-agent /contact [~sun %contacts] %fact %contact-update-1 !>([%full now.bowl con-sun]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%peer ~sun con-sun]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] contact-news-1+!>([%peer ~sun con-sun]))
==
:: ~sun appears in peers
::
Expand All @@ -482,7 +482,7 @@
;< caz=(list card) b (do-poke %contact-action-1 !>([%spot ~sun ~]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/v1/news] %contact-news-1 !>([%page ~sun con-sun ~]))
:~ (ex-fact ~[/v1/news] contact-news-1+!>([%page ~sun con-sun ~]))
==
:: ~sun contact page is edited
::
Expand All @@ -493,8 +493,8 @@
;< caz=(list card) b (do-poke %contact-action-1 !>([%edit ~sun con-mod]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c (~(uni by con-sun) con-mod))]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%page ~sun con-sun con-mod]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c (~(uni by con-sun) con-mod))]))
(ex-fact ~[/v1/news] contact-news-1+!>([%page ~sun con-sun con-mod]))
==
:: despite the edit, ~sun peer contact is unchanged
::
Expand Down Expand Up @@ -525,8 +525,8 @@
;< caz=(list card) b (do-poke %contact-action-1 !>([%wipe ~[~sun]]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%wipe ~sun]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] contact-news-1+!>([%wipe ~sun]))
==
:: ~sun contact page is removed
::
Expand Down Expand Up @@ -567,8 +567,8 @@
(do-agent /contact [~sun %contacts] %fact %contact-update-1 !>([%full now.bowl con-sun]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%peer ~sun con-sun]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] contact-news-1+!>([%peer ~sun con-sun]))
==
:: ~sun appears in peers
::
Expand All @@ -585,7 +585,7 @@
;< caz=(list card) b (do-poke %contact-action-1 !>([%spot ~sun ~]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/v1/news] %contact-news-1 !>([%page ~sun con-sun ~]))
:~ (ex-fact ~[/v1/news] contact-news-1+!>([%page ~sun con-sun ~]))
==
:: ~sun contact page is edited
::
Expand All @@ -596,8 +596,8 @@
;< caz=(list card) b (do-poke %contact-action-1 !>([%edit ~sun con-mod]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c (~(uni by con-sun) con-mod))]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%page ~sun con-sun con-mod]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c (~(uni by con-sun) con-mod))]))
(ex-fact ~[/v1/news] contact-news-1+!>([%page ~sun con-sun con-mod]))
==
:: ~sun is dropped
::
Expand All @@ -606,8 +606,8 @@
;< ~ b
%+ ex-cards caz
:~ (ex-task /contact [~sun %contacts] %leave ~)
(ex-fact ~[/news] %contact-news !>([~sun ~]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%peer ~sun ~]))
(ex-fact ~[/news] contact-news+!>([~sun ~]))
(ex-fact ~[/v1/news] contact-news-1+!>([%peer ~sun ~]))
==
:: ~sun is not found in peers
::
Expand Down Expand Up @@ -650,21 +650,21 @@
(do-agent /contact [~sun %contacts] %fact %contact-update-1 !>([%full now.bowl con-sun]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/news] %contact-news !>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] %contact-news-1 !>([%peer ~sun con-sun]))
:~ (ex-fact ~[/news] contact-news+!>([~sun (to-contact-0:c con-sun)]))
(ex-fact ~[/v1/news] contact-news-1+!>([%peer ~sun con-sun]))
==
:: ~sun is added to contacts
::
;< ~ b (set-src our.bowl)
;< caz=(list card) b (do-poke %contact-action-1 !>([%spot ~sun ~]))
;< ~ b
%+ ex-cards caz
:~ (ex-fact ~[/v1/news] %contact-news-1 !>([%page ~sun con-sun ~]))
:~ (ex-fact ~[/v1/news] contact-news-1+!>([%page ~sun con-sun ~]))
==
:: ~sun is snubbed
::
;< ~ b (set-src our.bowl)
;< caz=(list card) b (do-poke %contact-action-1 !>([%snub ~[~sun]]))
;< caz=(list card) b (do-poke contact-action-1+!>([%snub ~[~sun]]))
;< ~ b
%+ ex-cards caz
:~ (ex-task /contact [~sun %contacts] %leave ~)
Expand Down

0 comments on commit 043cca9

Please sign in to comment.