mirror of
https://github.com/documize/community.git
synced 2025-07-19 21:29:42 +02:00
fix section test, remove dead code.
This commit is contained in:
parent
a8b0754393
commit
d5f30b440e
4 changed files with 11 additions and 94 deletions
|
@ -75,10 +75,6 @@ func validateToken(ptoken string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func secretsJSON(token string) string {
|
|
||||||
return `{"token":"` + strings.TrimSpace(token) + `"}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command to run the various functions required...
|
// Command to run the various functions required...
|
||||||
func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
|
|
|
@ -27,18 +27,18 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command is an end-point...
|
// Command is an end-point...
|
||||||
func (ts *testsection) Command(w http.ResponseWriter, r *http.Request) {}
|
func (ts *testsection) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {}
|
||||||
|
|
||||||
var didRefresh bool
|
var didRefresh bool
|
||||||
|
|
||||||
// Refresh existing data, returning data in the format of the target system
|
// Refresh existing data, returning data in the format of the target system
|
||||||
func (ts *testsection) Refresh(meta, data string) string {
|
func (ts *testsection) Refresh(ctx *provider.Context, meta, data string) string {
|
||||||
didRefresh = true
|
didRefresh = true
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render converts data in the target system format into HTML
|
// Render converts data in the target system format into HTML
|
||||||
func (*testsection) Render(meta, data string) string {
|
func (*testsection) Render(ctx *provider.Context, meta, data string) string {
|
||||||
return "testsection " + data
|
return "testsection " + data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,13 +54,15 @@ func (*testsection) Meta() provider.TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSection(t *testing.T) {
|
func TestSection(t *testing.T) {
|
||||||
if _, ok := provider.Refresh("testsection", "", ""); !ok {
|
ctx := provider.NewContext("_orgid_", "_userid_")
|
||||||
|
|
||||||
|
if _, ok := provider.Refresh("testsection", ctx, "", ""); !ok {
|
||||||
t.Error("did not find 'testsection' smart section (1)")
|
t.Error("did not find 'testsection' smart section (1)")
|
||||||
}
|
}
|
||||||
if !didRefresh {
|
if !didRefresh {
|
||||||
t.Error("did not run the test Refresh method")
|
t.Error("did not run the test Refresh method")
|
||||||
}
|
}
|
||||||
out, ok := provider.Render("testsection", "meta", "dingbat")
|
out, ok := provider.Render("testsection", ctx, "meta", "dingbat")
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("did not find 'testsection' smart section (2)")
|
t.Error("did not find 'testsection' smart section (2)")
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,24 +91,6 @@ func testPages(t *testing.T, c *documize.Client, testFolder, testFile, testData
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
revs, err := c.GetDocumentPageRevisions(testFile, pagesAdded[0].RefID)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
} else {
|
|
||||||
diff, err2 := c.GetDocumentPageDiff(testFile, pagesAdded[0].RefID, revs[0].RefID)
|
|
||||||
if err2 != nil {
|
|
||||||
t.Error(err2)
|
|
||||||
} else {
|
|
||||||
t.Logf("INFO: Revised single doc page diff: %s", string(diff))
|
|
||||||
}
|
|
||||||
err = c.RollbackDocumentPage(testFile, pagesAdded[0].RefID, revs[0].RefID)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
} else {
|
|
||||||
t.Logf("INFO: Rolled-back revised single doc page %s", revs[0].RefID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = c.DeleteDocumentPage(testFile, pagesAdded[0].RefID)
|
err = c.DeleteDocumentPage(testFile, pagesAdded[0].RefID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|
63
sdk/pages.go
63
sdk/pages.go
|
@ -171,69 +171,6 @@ func (c *Client) UpdateDocumentPage(pg *entity.Page) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDocumentPageRevisions returns all the previous versions of a given page in a document.
|
|
||||||
func (c *Client) GetDocumentPageRevisions(documentID, pageID string) ([]entity.Revision, error) {
|
|
||||||
req, err := http.NewRequest("GET", c.BaseURL+"/api/documents/"+documentID+"/pages/"+pageID+"/revisions", nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req.Header.Add(HeaderAuthTokenName, c.Auth.Token)
|
|
||||||
resp, err := c.Client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close() // ignore error
|
|
||||||
revs := make([]entity.Revision, 0, 3)
|
|
||||||
dec := json.NewDecoder(resp.Body)
|
|
||||||
err = dec.Decode(&revs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return revs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDocumentPageDiff returns html showing the difference between the given page revision and the current version of
|
|
||||||
// a given page in a document.
|
|
||||||
func (c *Client) GetDocumentPageDiff(documentID, pageID, revID string) ([]byte, error) {
|
|
||||||
req, err := http.NewRequest("GET", c.BaseURL+"/api/documents/"+documentID+"/pages/"+pageID+"/revisions/"+revID, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req.Header.Add(HeaderAuthTokenName, c.Auth.Token)
|
|
||||||
resp, err := c.Client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close() // ignore error
|
|
||||||
diff, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return diff, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RollbackDocumentPage reverts the given document page back to the chosen revision.
|
|
||||||
func (c *Client) RollbackDocumentPage(documentID, pageID, revID string) error {
|
|
||||||
req, err := http.NewRequest("POST", c.BaseURL+"/api/documents/"+documentID+"/pages/"+pageID+"/revisions/"+revID, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
req.Header.Add(HeaderAuthTokenName, c.Auth.Token)
|
|
||||||
resp, err := c.Client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close() // ignore error
|
|
||||||
diff, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if isError(string(diff)) {
|
|
||||||
return errors.New(trimErrors(string(diff)))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChangeDocumentPageLevel sets the levels of the pages in the PageLevelRequestModel for the given document.
|
// ChangeDocumentPageLevel sets the levels of the pages in the PageLevelRequestModel for the given document.
|
||||||
func (c *Client) ChangeDocumentPageLevel(documentID string, plrm *[]models.PageLevelRequestModel) error {
|
func (c *Client) ChangeDocumentPageLevel(documentID string, plrm *[]models.PageLevelRequestModel) error {
|
||||||
b, err := json.Marshal(plrm)
|
b, err := json.Marshal(plrm)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue