@@ -35,15 +35,91 @@ describe('netlify-cli', function() {
3535 this . context = {
3636 ui : mockUi ,
3737 project : stubProject ,
38- distDir : 'my-dest -dir' ,
38+ distDir : 'my-dist -dir' ,
3939 revisionData : {
40- revisionKey : 'v1.0.0@ 1234567'
40+ revisionKey : 'v1.0.0+ 1234567'
4141 } ,
4242 deployTarget : 'my-production' ,
4343 config : {
4444 'netlify-cli' : {
45+ siteId : 'my-project' ,
46+ authToken : 'my-auth-token'
4547 }
4648 }
4749 } ;
4850 } ) ;
51+
52+ it ( 'has a name' , function ( ) {
53+ const plugin = Plugin . createDeployPlugin ( { name : 'netlify-cli' } ) ;
54+
55+ assert . equal ( plugin . name , 'netlify-cli' ) ;
56+ } ) ;
57+
58+ describe ( 'implements correct hooks' , function ( ) {
59+ it ( 'upload' , function ( ) {
60+ const plugin = Plugin . createDeployPlugin ( { name : 'netlify-cli' } ) ;
61+
62+ assert . equal ( typeof plugin . upload , 'function' , 'Implements didPrepare' ) ;
63+ } ) ;
64+ } ) ;
65+
66+ describe ( 'configure' , function ( ) {
67+ describe ( 'requires config' , function ( ) {
68+ it ( 'siteId' , function ( ) {
69+ const plugin = Plugin . createDeployPlugin ( { name : 'netlify-cli' } ) ;
70+
71+ this . context . config [ 'netlify-cli' ] . siteId = undefined ;
72+
73+ plugin . beforeHook ( this . context ) ;
74+
75+ assert . throws ( ( ) => plugin . configure ( this . context ) , 'Missing required config: `siteId`' ) ;
76+ } ) ;
77+
78+ it ( 'authToken' , function ( ) {
79+ const plugin = Plugin . createDeployPlugin ( { name : 'netlify-cli' } ) ;
80+
81+ this . context . config [ 'netlify-cli' ] . authToken = undefined ;
82+
83+ plugin . beforeHook ( this . context ) ;
84+
85+ assert . throws ( ( ) => plugin . configure ( this . context ) , 'Missing required config: `authToken`' ) ;
86+ } ) ;
87+ } ) ;
88+
89+ describe ( 'has default config' , function ( ) {
90+ it ( 'distDir' , function ( ) {
91+ const plugin = Plugin . createDeployPlugin ( { name : 'netlify-cli' } ) ;
92+
93+ plugin . beforeHook ( this . context ) ;
94+ plugin . configure ( this . context ) ;
95+
96+ assert . equal ( plugin . readConfig ( 'distDir' ) , 'my-dist-dir' ) ;
97+ } ) ;
98+
99+ it ( 'revisionKey' , function ( ) {
100+ const plugin = Plugin . createDeployPlugin ( { name : 'netlify-cli' } ) ;
101+
102+ plugin . beforeHook ( this . context ) ;
103+ plugin . configure ( this . context ) ;
104+
105+ assert . equal ( plugin . readConfig ( 'revisionKey' ) , 'v1.0.0+1234567' ) ;
106+ } ) ;
107+ } ) ;
108+ } ) ;
109+
110+ describe ( 'upload' , function ( ) {
111+ it ( 'deploys to netlify' , function ( ) {
112+ const plugin = Plugin . createDeployPlugin ( { name : 'netlify-cli' } ) ;
113+ const stub = this . sinon . stub ( plugin , '_exec' ) ;
114+
115+ plugin . beforeHook ( this . context ) ;
116+ plugin . configure ( this . context ) ;
117+ plugin . upload ( ) ;
118+
119+ this . sinon . assert . calledWithExactly ( stub ,
120+ 'NETLIFY_AUTH_TOKEN=my-auth-token ' +
121+ 'NETLIFY_SITE_ID=my-project ' +
122+ 'node_modules/.bin/netlify deploy --prod --dir my-dist-dir --message v1.0.0+1234567' ) ;
123+ } ) ;
124+ } ) ;
49125} ) ;
0 commit comments