Skip to content

Commit

Permalink
Merge pull request #126 from jsniemela/master
Browse files Browse the repository at this point in the history
Added unit tests and two other small changes
  • Loading branch information
dularion committed Mar 6, 2016
2 parents 6ef5759 + 5be7f70 commit b9044f1
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ <h1>
</div>
<div class="col-sm-2">
<label>IMDB Link</label>
<p class="data-display"><a href="http://www.imdb.com/title/{{movie.imdb_id}}">{{movie.title}}</a></p>
<p class="data-display"><a target="_blank" href="http://www.imdb.com/title/{{movie.imdb_id}}">{{movie.title}}</a></p>
</div>
<div class="col-sm-2">
<label>Rating</label>
<p class="data-display">{{movie.vote_average}}</p>
<p class="data-display">{{movie.vote_average}}/10</p>
</div>
<div class="col-sm-2">
<label>Rating Count</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1>
</div>
<div class="col-sm-2">
<label>Rating</label>
<p class="data-display">{{show.vote_average}}</p>
<p class="data-display">{{show.vote_average}}/10</p>
</div>
<div class="col-sm-2">
<label>Rating Count</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ul class="info-list">
<li><strong>Released: </strong> {{media.release_date.substring(0,4) || media.first_air_date.substring(0,4)}}</li>
<li><strong>IMDB: </strong> <a target="_blank" href="http://www.imdb.com/title/{{media.imdb_id}}">{{media.name || media.title}}</a></li>
<li><strong>Rating: </strong> {{media.vote_average}} ({{media.vote_count}} votes)</li>
<li><strong>Rating: </strong> {{media.vote_average}}/10 ({{media.vote_count}} votes)</li>
</ul>

<hr/>
Expand Down
27 changes: 19 additions & 8 deletions test/unit/streama/FileSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(File)
class FileSpec extends Specification {
void "test file constraints for sha256Hex and quality"() {
setup:
def file0 = File.newInstance()
def file1 = File.newInstance()
def file2 = File.newInstance()
def file3 = File.newInstance()

def setup() {
}

def cleanup() {
}
//string length 64
file0.sha256Hex = 'TuFk8RjfG4AYQYT0pmK6vaBivF449S2UNmhXQEbE9Sr3FFFX44n4lyPq2jOQkUUv'
//string length 65, too long
file1.sha256Hex = '8iSuxvAT7NGS5lAa1eOIw1MlKZhO14m9p3ZQSQ08VilBGqniVA1EeLvyxKj8MNW3g'
//quality 720p is on the allowed list
file2.quality = '720p'
//quality 721p is not on the allowed list
file3.quality = '721p'

void "test something"() {
expect:
file0.validate() == true
file1.validate() == false
file2.validate() == true
file3.validate() == false
}
}
23 changes: 23 additions & 0 deletions test/unit/streama/GenreSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(Genre)
class GenreSpec extends Specification {

void "test constraints with null values on apiId and name"() {
setup:
def genre0 = Genre.newInstance()
def genre1 = Genre.newInstance()

genre0.apiId = null
genre1.name = null
expect:
genre0.validate() == false
genre1.validate() == false
}
}
48 changes: 48 additions & 0 deletions test/unit/streama/SettingsControllerSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package streama

import grails.test.mixin.*
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(SettingsController)
@Mock(Settings)
class SettingsControllerSpec extends Specification {

void "test settings instance is null, status 404"() {

when:
def settingsController = SettingsController.newInstance()
request.method = 'POST'
settingsController.save(null)

then:
status == 404
}

void "test settings instance not valid, status 406"() {
when:
def settingsController = SettingsController.newInstance()
mockFor(Settings)
def settingsMock = new Settings(settingsKey: null)
request.method = 'POST'
settingsController.save(settingsMock)

then:
status == 406
}

void "test settings instance is valid, status 201"() {
when:
def settingsController = SettingsController.newInstance()
mockFor(Settings)
def settingsMock = new Settings(settingsKey: 'abcd')
request.method = 'POST'
settingsController.save(settingsMock)

then:
status == 201
}

}
21 changes: 21 additions & 0 deletions test/unit/streama/SettingsServiceSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package streama

import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.Specification

@TestFor(SettingsService)
@Mock(Settings)
class SettingsServiceSpec extends Specification {
void "test getting base URL"() {
setup:
def settingsService = SettingsService.newInstance()
def settings = [
new Settings(settingsKey: 'Base URL', value: 'http://localhost:8080/streama')
]
settings*.save(flush: true)
def result = settingsService.getBaseUrl()
expect:
result == 'http://localhost:8080/streama'
}
}
25 changes: 25 additions & 0 deletions test/unit/streama/SettingsSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(Settings)
class SettingsSpec extends Specification {

void "test constraints for settingsKey being null"() {
setup:
def settings0 = Settings.newInstance()
def settings1 = Settings.newInstance()
//settingsKey is null, not valid
settings0.settingsKey = null
//settingsKey not null, valid
settings1.settingsKey = 'abcd'

expect:
settings0.validate() == false
settings1.validate() == true
}
}
41 changes: 34 additions & 7 deletions test/unit/streama/TvShowSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Shared
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(TvShow)
class TvShowSpec extends Specification {

def setup() {
}

def cleanup() {
}
class TvShowSpec extends Specification {
@Shared tvshow0, tvshow1, tvshow2
def setup() {
tvshow0 = TvShow.newInstance()
tvshow1 = TvShow.newInstance()
tvshow2 = TvShow.newInstance()
}
void "test tvshow constraints for overview length"() {
setup:
//string length 4, good length
tvshow0.overview = 'asdf'
//String length 5000, good length
tvshow1.overview = 't' * 5000
//String length 5001, too long
tvshow2.overview = 'f' * 5001
//Name is not null
tvshow0.name = 'testname'
tvshow1.name = 'testname'
tvshow2.name = 'testname'

void "test something"() {
expect:
tvshow0.validate() == true
tvshow1.validate() == true
tvshow2.validate() == false
}
void "test tvshow contraints for name"() {
setup:
//Name is not null
tvshow0.name = 'testname'
//Name is null, not allowed
tvshow1.name = null
expect:
tvshow0.validate() == true
tvshow1.validate() == false
}
}
51 changes: 51 additions & 0 deletions test/unit/streama/UserSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(User)
class UserSpec extends Specification {

void "test constraints for username uniqueness"() {
setup:
def user0 = User.newInstance()
def user1 = User.newInstance()
mockForConstraintsTests(User, [user1])

//username is unique
user0.username = 'testuser'
//username is unique (for now)
user1.username = 'testuser2'
//username is not unique
def user2 = new User(username: 'testuser2')

expect:
user0.validate() == true
user1.validate() == true
user2.validate() == false
}
void "test constraints for username being blank"() {
setup:
def user0 = User.newInstance()

user0.username = ''

expect:
user0.validate() == false
}
void "test constraints for password being blank"() {
setup:
def user0 = User.newInstance()
def user1 = User.newInstance()

user0.password = ''
user1.password = 'testpass'

expect:
user0.validate() == false
user1.validate() == true
}
}
22 changes: 17 additions & 5 deletions test/unit/streama/VideoSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ import spock.lang.Specification
@TestFor(Video)
class VideoSpec extends Specification {

def setup() {
}
void "test video constraints for overview size"() {
setup:
def video0 = Video.newInstance()
def video1 = Video.newInstance()
def video2 = Video.newInstance()

def cleanup() {
}
//string length 4, good length
video0.overview = 'test'
//String length 5000, good length
video1.overview = 't' * 5000
//String length 5001, too long
video2.overview = 'f' * 5001

void "test something"() {
video0.dateCreated = null
video0.lastUpdated = null
expect:
video0.validate() == true
video1.validate() == true
video2.validate() == false
}
}

0 comments on commit b9044f1

Please sign in to comment.