mirror of https://github.com/Budibase/budibase.git
6 changed files with 120 additions and 11 deletions
@ -0,0 +1,11 @@ |
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
|||
|
|||
exports[`/views fetch returns a list of all the views that exist in the instance database 1`] = ` |
|||
Object { |
|||
"by_type": Object { |
|||
"map": "function (doc) { |
|||
emit([doc.type], doc._id); |
|||
}", |
|||
}, |
|||
} |
|||
`; |
|||
@ -0,0 +1,80 @@ |
|||
const supertest = require("supertest"); |
|||
const app = require("../../../../app"); |
|||
const { createInstanceDatabase, createModel, destroyDatabase } = require("./couchTestUtils"); |
|||
|
|||
|
|||
const TEST_INSTANCE_ID = "testing-123"; |
|||
|
|||
describe("/views", () => { |
|||
let request; |
|||
let server; |
|||
|
|||
beforeAll(async () => { |
|||
server = await app({ |
|||
config: { |
|||
port: 3000 |
|||
} |
|||
}); |
|||
request = supertest(server); |
|||
}); |
|||
|
|||
afterAll(async () => { |
|||
server.close(); |
|||
}) |
|||
|
|||
describe("create", () => { |
|||
beforeEach(async () => { |
|||
await createInstanceDatabase(TEST_INSTANCE_ID); |
|||
}); |
|||
|
|||
afterEach(async () => { |
|||
await destroyDatabase(TEST_INSTANCE_ID); |
|||
}); |
|||
|
|||
it("returns a success message when the view is successfully created", done => { |
|||
request |
|||
.post(`/api/${TEST_INSTANCE_ID}/views`) |
|||
.send({ |
|||
name: "TestView", |
|||
map: `function(doc) {
|
|||
if (doc.id) { |
|||
emit(doc.name, doc._id); |
|||
} |
|||
}`,
|
|||
reduce: `function(keys, values) { }` |
|||
}) |
|||
.set("Accept", "application/json") |
|||
.expect('Content-Type', /json/) |
|||
.expect(200) |
|||
.end(async (err, res) => { |
|||
expect(res.body.message).toEqual("View TestView created successfully."); |
|||
expect(res.body.id).toEqual("_design/database"); |
|||
done(); |
|||
}); |
|||
}) |
|||
}); |
|||
|
|||
describe("fetch", () => { |
|||
beforeEach(async () => { |
|||
await createInstanceDatabase(TEST_INSTANCE_ID); |
|||
await createModel(TEST_INSTANCE_ID); |
|||
}); |
|||
|
|||
afterEach(async () => { |
|||
await destroyDatabase(TEST_INSTANCE_ID); |
|||
}); |
|||
|
|||
it("returns a list of all the views that exist in the instance database", done => { |
|||
request |
|||
.get(`/api/${TEST_INSTANCE_ID}/views`) |
|||
.set("Accept", "application/json") |
|||
.expect('Content-Type', /json/) |
|||
.expect(200) |
|||
.end(async (_, res) => { |
|||
expect(res.body.by_type).toBeDefined(); |
|||
expect(res.body).toMatchSnapshot(); |
|||
done(); |
|||
}); |
|||
}) |
|||
}); |
|||
}); |
|||
Loading…
Reference in new issue