Example #1
0
func TestImport(t *testing.T) {
	require := require.New(t)

	user := &repo.User{testUser}
	udb, err := user.DB()
	require.Nil(err, "Error connecting to User DB: %s", err)

	var allUserDocs, allBundleDocs map[string]interface{}
	err = udb.AllDocs(&allUserDocs, pouchdb.Options{})
	require.Nil(err, "Error fetching AllDocs(): %s", err)

	// Remove the revs, because they're random
	urows := allUserDocs["rows"].([]interface{})
	uids := make([]string, len(urows))
	for i, row := range urows {
		uids[i] = row.(map[string]interface{})["id"].(string)
	}
	require.DeepEqual(expectedUserDBIDs, uids, "User DB IDs")

	bdb, err := repo.NewDB("bundle-iw5x7ie66fsepm67hey2fqjms6fywi6v")
	require.Nil(err, "Error connecting to Bundle DB: %s", err)

	if err := bdb.AllDocs(&allBundleDocs, pouchdb.Options{}); err != nil {
		t.Fatalf("Error fetching AllDocs(): %s", err)
	}
	// Remove the revs, because they're random
	brows := allBundleDocs["rows"].([]interface{})
	bids := make([]string, len(brows))
	for i, row := range brows {
		bids[i] = row.(map[string]interface{})["id"].(string)
	}
	require.DeepEqual(expectedBundleDBIDs, bids, "Bundle DB IDs")
}
Example #2
0
func testImport(t *testing.T) {
	importMu.Lock()
	if importComplete {
		return
	}
	defer importMu.Unlock()
	require := require.New(t)
	fbb, err := os.Open(fbbFile)
	require.Nil(err, "Error reading %s: %s", fbbFile, err)

	user := &repo.User{testUser}
	err = repo.Import(user, fbb)
	require.Nil(err, "Error importing file: %+v", err)

	importComplete = true
}
Example #3
0
func TestCard2(t *testing.T) {
	require := require.New(t)

	testImport(t)

	u := repo.User{testUser}

	card, err := u.GetCard("card-iw5x7ie66fsepm67hey2fqjms6fywi6v.4WpHslICjKMtkmw-KKpSJECrnuc.1")
	require.Nil(err, "Error fetching card: %s", err)
	require.NotNil(card, "Card is nil")

	body, _, err := card.Body()
	require.Nil(err, "Unable to fetch the card's body: %s", err)
	body = revRE.ReplaceAllString(body, `"_rev":"X-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"`)
	body = iframeRE.ReplaceAllString(body, `iframeID: 'xxxxxxxxxxxxxxxx'`)
	require.LinesEqual(expectedBody2, body, "Card's body")
}
Example #4
0
func TestRepo(t *testing.T) {
	require := require.New(t)
	fbb, err := ioutil.ReadFile(fbbFile)
	require.Nil(err, "Error reading %s: %s", fbbFile, err)

	pkg := &fb.Package{}
	err = json.Unmarshal(fbb, pkg)
	require.Nil(err, "Error unmarshaling Art.fbb: %s", err)

	db := DB()
	th := pkg.Themes[0]
	err = db.Save(th)
	require.Nil(err, "Error saving theme: %s", err)

	var i interface{}
	err = db.Get(th.DocID(), &i, pouchdb.Options{})
	require.Nil(err, "Error re-fetching Theme: %s", err)

	e := Expected(th.DocID(), i.(map[string]interface{})["_rev"].(string))
	require.DeepEqualJSON(e, i, "Theme")
}