Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Add specs for trashing and deleting notes
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjswift committed Apr 11, 2011
1 parent f9f120e commit 760620e
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/test/scala/SimplenoteApiSpec.scala
@@ -1,7 +1,9 @@
package com.bryanjswift.simplenote.net

import com.bryanjswift.simplenote.model.Credentials
import com.bryanjswift.simplenote.Constants
import com.bryanjswift.simplenote.model.{ Credentials, Note }
import org.apache.http.HttpStatus
import org.joda.time.DateTime
import org.scalatest.WordSpec
import org.scalatest.matchers.ShouldMatchers

Expand All @@ -12,13 +14,15 @@ class SimplenoteApiSpec extends WordSpec with ShouldMatchers {
val unauthorized = new SimplenoteApi(userAgent)

"SimplenoteApi" should {

"return Credentials with valid auth value on successful login" in {
val response = unauthorized.login(credentials.email, credentials.password)
response.status should be (HttpStatus.SC_OK)
response.payload.email should be (credentials.email)
response.payload.auth.length should be > 0
response.payload.password should be (null)
}

"return with unauthorized status on unsuccessful login" in {
val response = unauthorized.login(badCredentials.email, badCredentials.password)
response.status should not be (HttpStatus.SC_UNAUTHORIZED)
Expand All @@ -28,8 +32,11 @@ class SimplenoteApiSpec extends WordSpec with ShouldMatchers {
}

"Properly credentialed SimplenoteApi" should {
import scala.collection.JavaConversions._
val loginResponse = unauthorized.login(credentials.email, credentials.password)
val authorized = unauthorized.using(loginResponse.payload)
val now = new DateTime
val localNote = new Note(false, now, now, List[String](), List[String](), "Just a test")

"be able to list the index" in {
val response = authorized.index
Expand All @@ -49,8 +56,39 @@ class SimplenoteApiSpec extends WordSpec with ShouldMatchers {
noteResponse.payload should not be (null)
val getNote = noteResponse.payload
getNote.key should be (indexNote.key)
getNote.createdate should be (indexNote.createdate)
getNote.content.length should be > (0)
}

"be able to move a note to Trash" in {
val indexResponse = authorized.index
indexResponse.status should be (HttpStatus.SC_OK)
indexResponse.payload.count should be > (0)
val indexNote = indexResponse.payload.notes.get(0)
val key = indexNote.key
val note = Note.fromKey(key)
val trashResponse = authorized.trash(note)
trashResponse.status should be (HttpStatus.SC_OK)
trashResponse.payload should not be (null)
trashResponse.payload.key should be (key)
trashResponse.payload.deleted should be (true)
// set note back to active
authorized.update(Note.fromKey(key).setDeleted(false))
}

"be able to create a new note and subsequently delete it" in {
val initialIndexResponse = authorized.index
initialIndexResponse.status should be (HttpStatus.SC_OK)
val count = initialIndexResponse.payload.count
val createResponse = authorized.create(localNote)
createResponse.status should be (HttpStatus.SC_OK)
createResponse.payload should not be (null)
createResponse.payload.key should not be (null)
createResponse.payload.key.length should be > (0)
val tmpNote = Note.fromKey(createResponse.payload.key)
val trashResponse = authorized.trash(tmpNote)
trashResponse.status should be (HttpStatus.SC_OK)
val deleteResponse = authorized.delete(tmpNote)
deleteResponse.status should be (HttpStatus.SC_OK)
}
}
}

0 comments on commit 760620e

Please sign in to comment.