Skip to content

Commit

Permalink
add some tests for osem_measurements_archive
Browse files Browse the repository at this point in the history
  • Loading branch information
noerw committed Oct 19, 2018
1 parent 4d33fa9 commit 18a698b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/testthat/test_archive.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
source('testhelpers.R')

context('osem_box_to_archivename()')

try({
boxes = osem_boxes(grouptag = 'ifgi')
box = filter(boxes, row_number() == 1)
})

test_that('osem_box_to_archive_name does the correct character replacements', {
b = data.frame(
name = 'aA1._- äß!"?$%&/',
X_id = 'UUID'
)

archivename = opensensmapr:::osem_box_to_archivename(b)
expect_equal(archivename, 'UUID-aA1._-__________')
})

test_that('osem_box_to_archive_name works for one box', {
if (is.null(box)) skip('no box data could be fetched')

archivename = opensensmapr:::osem_box_to_archivename(box)
expect_length(archivename, 1)
expect_type(archivename, 'character')
})

test_that('osem_box_to_archive_name works for multiple boxes', {
if (is.null(boxes)) skip('no box data available')

archivename = opensensmapr:::osem_box_to_archivename(boxes)
expect_length(archivename, nrow(boxes))
expect_type(archivename, 'character')
})

context('osem_measurements_archive()')

test_that('osem_measurements_archive works for one box', {
if (is.null(box)) skip('no box data could be fetched')

m = osem_measurements_archive(box, as.POSIXlt('2018-08-08'))
expect_length(m, nrow(box$sensors[[1]]) + 1) # one column for each sensor + createdAt
expect_s3_class(m, c('osem_measurements', 'tbl_df'))
})

test_that('osem_measurements_archive fails for multiple boxes', {
if (is.null(boxes)) skip('no box data available')

expect_error(
osem_measurements_archive(boxes, as.POSIXlt('2018-08-08')),
'this function only works for exactly one senseBox!'
)
})

0 comments on commit 18a698b

Please sign in to comment.