github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/core/api/store/store_test.go (about)

     1  // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
     2  //
     3  // This software (Documize Community Edition) is licensed under
     4  // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
     5  //
     6  // You can operate outside the AGPL restrictions by purchasing
     7  // Documize Enterprise Edition and obtaining a commercial license
     8  // by contacting <sales@documize.com>.
     9  //
    10  // https://documize.com
    11  
    12  package store
    13  
    14  import (
    15  	"testing"
    16  
    17  	"github.com/documize/community/core/api/plugins"
    18  	api "github.com/documize/community/core/convapi"
    19  	"github.com/documize/community/core/log"
    20  )
    21  
    22  func TestExportAs(t *testing.T) {
    23  	err := plugins.LibSetup()
    24  	if err == nil {
    25  		// t.Error("did not error with missing config.json")
    26  	}
    27  	defer log.IfErr(plugins.Lib.KillSubProcs())
    28  
    29  	htm := "<p>some html</p>"
    30  
    31  	exp, err := ExportAs("html", htm)
    32  	if err != nil {
    33  		t.Error(err)
    34  	}
    35  	if string(exp.File) != htm {
    36  		t.Error("html returned not as expected: " + string(exp.File))
    37  	}
    38  
    39  	// log.TestIfErr = true
    40  	_, err = ExportAs("XXXXX", htm)
    41  	if err == nil /* || log.TestIfErr */ {
    42  		t.Error("did not error as expected")
    43  	}
    44  }
    45  
    46  func TestConvertFileResult(t *testing.T) {
    47  	fn := "afile"
    48  	doc := ConvertFileResult(fn, &api.DocumentConversionResponse{}) // should not panic
    49  	if doc.Location != fn {
    50  		t.Error("filename not passed through")
    51  	}
    52  	doc = ConvertFileResult(fn, nil) // should not panic
    53  	if doc.Location != fn {
    54  		t.Error("filename not passed through")
    55  	}
    56  	rj := "Romeo & Juliet"
    57  	doc = ConvertFileResult(fn, &api.DocumentConversionResponse{
    58  		Pages: []api.Page{{Title: rj}},
    59  	})
    60  	if doc.Title != rj || doc.Slug != "romeo-juliet" {
    61  		t.Error("title not passed through correctly")
    62  	}
    63  }