@@ -13,6 +13,52 @@ module('Model | Crate', function (hooks) {
1313 this . store = this . owner . lookup ( 'service:store' ) ;
1414 } ) ;
1515
16+ module ( 'setTrustpubOnlyTask' , function ( ) {
17+ test ( 'enables trustpub_only' , async function ( assert ) {
18+ let user = this . db . user . create ( ) ;
19+ this . authenticateAs ( user ) ;
20+
21+ let crate = this . db . crate . create ( { trustpubOnly : false } ) ;
22+ this . db . version . create ( { crate } ) ;
23+
24+ let crateRecord = await this . store . findRecord ( 'crate' , crate . name ) ;
25+ assert . false ( crateRecord . trustpub_only ) ;
26+ assert . false ( this . db . crate . findFirst ( { where : { id : { equals : crate . id } } } ) . trustpubOnly ) ;
27+
28+ await crateRecord . setTrustpubOnlyTask . perform ( true ) ;
29+ assert . true ( crateRecord . trustpub_only ) ;
30+ assert . true ( this . db . crate . findFirst ( { where : { id : { equals : crate . id } } } ) . trustpubOnly ) ;
31+ } ) ;
32+
33+ test ( 'disables trustpub_only' , async function ( assert ) {
34+ let user = this . db . user . create ( ) ;
35+ this . authenticateAs ( user ) ;
36+
37+ let crate = this . db . crate . create ( { trustpubOnly : true } ) ;
38+ this . db . version . create ( { crate } ) ;
39+
40+ let crateRecord = await this . store . findRecord ( 'crate' , crate . name ) ;
41+ assert . true ( crateRecord . trustpub_only ) ;
42+ assert . true ( this . db . crate . findFirst ( { where : { id : { equals : crate . id } } } ) . trustpubOnly ) ;
43+
44+ await crateRecord . setTrustpubOnlyTask . perform ( false ) ;
45+ assert . false ( crateRecord . trustpub_only ) ;
46+ assert . false ( this . db . crate . findFirst ( { where : { id : { equals : crate . id } } } ) . trustpubOnly ) ;
47+ } ) ;
48+
49+ test ( 'requires authentication' , async function ( assert ) {
50+ let crate = this . db . crate . create ( ) ;
51+ this . db . version . create ( { crate } ) ;
52+
53+ let crateRecord = await this . store . findRecord ( 'crate' , crate . name ) ;
54+
55+ await assert . rejects ( crateRecord . setTrustpubOnlyTask . perform ( true ) , function ( error ) {
56+ assert . deepEqual ( error . errors , [ { detail : 'must be logged in to perform that action' } ] ) ;
57+ return true ;
58+ } ) ;
59+ } ) ;
60+ } ) ;
61+
1662 module ( 'inviteOwner()' , function ( ) {
1763 test ( 'happy path' , async function ( assert ) {
1864 let user = this . db . user . create ( ) ;
0 commit comments