Skip to content

Commit 6885970

Browse files
committed
Add test for single FAQ creation in kbRoute
- Implemented a new test case 'add-single-faq-success' to validate the process of adding a single FAQ entry. - The test includes user signup, project creation, and verification of the FAQ entry's properties such as namespace, type, source, content, and tags. - Ensured that the API responses are correctly validated for successful FAQ addition.
1 parent 8395ae1 commit 6885970

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/kbRoute.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,66 @@ describe('KbRoute', () => {
918918
})
919919
}).timeout(20000)
920920

921+
it('add-single-faq-success', (done) => {
922+
var email = "test-signup-" + Date.now() + "@email.com";
923+
var pwd = "pwd";
924+
925+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
926+
projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
927+
928+
chai.request(server)
929+
.get('/' + savedProject._id + '/kb/namespace/all')
930+
.auth(email, pwd)
931+
.end((err, res) => {
932+
if (err) { console.error("err: ", err); }
933+
if (log) { console.log("res.body: ", res.body) }
934+
935+
res.should.have.status(200);
936+
expect(res.body.length).to.equal(1);
937+
938+
let namespace_id = res.body[0].id;
939+
940+
let content = {
941+
name: "Sample question",
942+
source: "Sample question",
943+
content: "Sample question\nSample answer",
944+
type: "faq",
945+
tags: ["tag1", "tag2"],
946+
namespace: namespace_id
947+
}
948+
949+
chai.request(server)
950+
.post('/' + savedProject._id + '/kb')
951+
.auth(email, pwd)
952+
.send(content)
953+
.end((err, res) => {
954+
if (err) { console.error("err: ", err); }
955+
if (log) { console.log("res.body: ", res.body) }
956+
957+
res.should.have.status(200);
958+
res.body.should.be.a('object');
959+
960+
let realResponse = res.body.data;
961+
expect(realResponse.value.namespace).to.equal(namespace_id);
962+
expect(realResponse.value.type).to.equal("faq");
963+
expect(realResponse.value.source).to.equal("Sample question");
964+
expect(realResponse.value.content).to.equal("Sample question\nSample answer");
965+
expect(realResponse.value.tags.length).to.equal(2);
966+
expect(realResponse.value.tags[0]).to.equal("tag1");
967+
expect(realResponse.value.tags[1]).to.equal("tag2");
968+
969+
done();
970+
971+
972+
});
973+
974+
});
975+
976+
977+
})
978+
});
979+
})
980+
921981
it('add-multiple-faqs-with-csv', (done) => {
922982

923983
var email = "test-signup-" + Date.now() + "@email.com";

0 commit comments

Comments
 (0)