@@ -107,14 +107,19 @@ func TestDownload(t *testing.T) {
107107 expectedDir : filepath .Join ("users" , "alice" ),
108108 flags : map [string ]string {"uuid" : "bogus-id" },
109109 },
110+ {
111+ requester : true ,
112+ expectedDir : filepath .Join ("teams" , "bogus-team" ),
113+ flags : map [string ]string {"exercise" : "bogus-exercise" , "track" : "bogus-track" , "team" : "bogus-team" },
114+ },
110115 }
111116
112117 for _ , tc := range testCases {
113118 tmpDir , err := ioutil .TempDir ("" , "download-cmd" )
114119 defer os .RemoveAll (tmpDir )
115120 assert .NoError (t , err )
116121
117- ts := fakeDownloadServer (strconv .FormatBool (tc .requester ))
122+ ts := fakeDownloadServer (strconv .FormatBool (tc .requester ), tc . flags [ "team" ] )
118123 defer ts .Close ()
119124
120125 v := viper .New ()
@@ -149,7 +154,7 @@ func TestDownload(t *testing.T) {
149154 }
150155}
151156
152- func fakeDownloadServer (requestor string ) * httptest.Server {
157+ func fakeDownloadServer (requestor , teamSlug string ) * httptest.Server {
153158 mux := http .NewServeMux ()
154159 server := httptest .NewServer (mux )
155160
@@ -165,11 +170,16 @@ func fakeDownloadServer(requestor string) *httptest.Server {
165170 fmt .Fprint (w , "" )
166171 })
167172
168- payloadBody := fmt .Sprintf (payloadTemplate , requestor , server .URL + "/" )
169173 mux .HandleFunc ("/solutions/latest" , func (w http.ResponseWriter , r * http.Request ) {
174+ team := "null"
175+ if teamSlug := r .FormValue ("team_id" ); teamSlug != "" {
176+ team = fmt .Sprintf (`{"name": "Bogus Team", "slug": "%s"}` , teamSlug )
177+ }
178+ payloadBody := fmt .Sprintf (payloadTemplate , requestor , team , server .URL + "/" )
170179 fmt .Fprint (w , payloadBody )
171180 })
172181 mux .HandleFunc ("/solutions/bogus-id" , func (w http.ResponseWriter , r * http.Request ) {
182+ payloadBody := fmt .Sprintf (payloadTemplate , requestor , "null" , server .URL + "/" )
173183 fmt .Fprint (w , payloadBody )
174184 })
175185
@@ -215,6 +225,7 @@ const payloadTemplate = `
215225 "handle": "alice",
216226 "is_requester": %s
217227 },
228+ "team": %s,
218229 "exercise": {
219230 "id": "bogus-exercise",
220231 "instructions_url": "http://example.com/bogus-exercise",
@@ -226,9 +237,9 @@ const payloadTemplate = `
226237 },
227238 "file_download_base_url": "%s",
228239 "files": [
229- "/file-1.txt",
230- "/subdir/file-2.txt",
231- "/file-3.txt"
240+ "/file-1.txt",
241+ "/subdir/file-2.txt",
242+ "/file-3.txt"
232243 ],
233244 "iteration": {
234245 "submitted_at": "2017-08-21t10:11:12.130z"
0 commit comments