Skip to content

Commit

Permalink
step 10 test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudarshan-21 committed May 27, 2024
1 parent 5014a06 commit 9dda478
Show file tree
Hide file tree
Showing 8 changed files with 917 additions and 740 deletions.
20 changes: 10 additions & 10 deletions tests/step-03/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const readCSV = require("../../src/csvReader");
const { parseQuery } = require("../../src/queryParser");
const { readCSV } = require("../../src/csvReader");
const { parseSelectQuery } = require("../../src/queryParser");

test("Read CSV File", async () => {
const data = await readCSV("./student.csv");
Expand All @@ -11,18 +11,18 @@ test("Read CSV File", async () => {

test("Parse SQL Query", () => {
const query = "SELECT id, name FROM student";
const parsed = parseQuery(query);
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [],
joinType: null,
isDistinct: false,
joinCondition: null,
groupByFields: null,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
joinTable: null,
joinType: null,
limit: null,
whereClauses: [],
});
});

test("Invalid Query Format", () => {
const query = "SELECT id, name";
expect(() => parseQuery(query)).toThrow();
});
17 changes: 11 additions & 6 deletions tests/step-04/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const readCSV = require("../../src/csvReader");
const { parseQuery } = require("../../src/queryParser");
const executeSELECTQuery = require("../../src/index");
const { readCSV } = require("../../src/csvReader");
const { parseSelectQuery } = require("../../src/queryParser");
const { executeSELECTQuery } = require("../../src/index");

test("Read CSV File", async () => {
const data = await readCSV("./student.csv");
Expand All @@ -12,14 +12,19 @@ test("Read CSV File", async () => {

test("Parse SQL Query", () => {
const query = "SELECT id, name FROM student";
const parsed = parseQuery(query);
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [],
joinType: null,
joinCondition: null,
groupByFields: null,
limit: null,
isDistinct: false,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
joinTable: null,
joinType: null,
whereClauses: [],
});
});

Expand Down
45 changes: 29 additions & 16 deletions tests/step-05/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const readCSV = require("../../src/csvReader");
const { parseQuery } = require("../../src/queryParser");
const executeSELECTQuery = require("../../src/index");
const { readCSV } = require("../../src/csvReader");
const { parseSelectQuery } = require("../../src/queryParser");
const { executeSELECTQuery } = require("../../src/index");

test("Read CSV File", async () => {
const data = await readCSV("./student.csv");
Expand All @@ -12,14 +12,19 @@ test("Read CSV File", async () => {

test("Parse SQL Query", () => {
const query = "SELECT id, name FROM student";
const parsed = parseQuery(query);
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [],
joinType: null,
joinCondition: null,
joinTable: null,
isDistinct: false,
limit: null,
joinType: null,
groupByFields: null,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
whereClauses: [],
});
});

Expand All @@ -34,29 +39,37 @@ test("Execute SQL Query", async () => {
});

test("Parse SQL Query with WHERE Clause", () => {
const query = "SELECT id, name FROM student WHERE age = 25";
const parsed = parseQuery(query);
const query = "SELECT id, name FROM student WHERE age = 30 AND name = John";
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
joinCondition: null,
joinTable: null,
limit: null,
isDistinct: false,
joinType: null,
groupByFields: null,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
whereClauses: [
{
field: "age",
operator: "=",
value: "25",
value: "30",
},
{
field: "name",
operator: "=",
value: "John",
},
],
joinType: null,
joinCondition: null,
joinTable: null,
});
});

test("Execute SQL Query with WHERE Clause", async () => {
const query = "SELECT id, name FROM student WHERE age = 25";
const query = "SELECT id, name FROM student WHERE age = 30 AND name = John";
const result = await executeSELECTQuery(query);
expect(result.length).toBe(1);
expect(result[0]).toHaveProperty("id");
expect(result[0]).toHaveProperty("name");
expect(result[0].id).toBe("2");
expect(result[0]).toEqual({ id: "1", name: "John" });
});
43 changes: 29 additions & 14 deletions tests/step-06/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const readCSV = require("../../src/csvReader");
const { parseQuery } = require("../../src/queryParser");
const executeSELECTQuery = require("../../src/index");
const { readCSV } = require("../../src/csvReader");
const { parseSelectQuery } = require("../../src/queryParser");
const { executeSELECTQuery } = require("../../src/index");

test("Read CSV File", async () => {
const data = await readCSV("./student.csv");
Expand All @@ -12,14 +12,19 @@ test("Read CSV File", async () => {

test("Parse SQL Query", () => {
const query = "SELECT id, name FROM student";
const parsed = parseQuery(query);
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [],
joinType: null,
joinCondition: null,
isDistinct: false,
joinTable: null,
limit: null,
joinType: null,
groupByFields: null,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
whereClauses: [],
});
});

Expand All @@ -35,20 +40,25 @@ test("Execute SQL Query", async () => {

test("Parse SQL Query with WHERE Clause", () => {
const query = "SELECT id, name FROM student WHERE age = 25";
const parsed = parseQuery(query);
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
isDistinct: false,
joinCondition: null,
joinTable: null,
joinType: null,
limit: null,
groupByFields: null,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
whereClauses: [
{
field: "age",
operator: "=",
value: "25",
},
],
joinType: null,
joinCondition: null,
joinTable: null,
});
});

Expand All @@ -63,10 +73,18 @@ test("Execute SQL Query with WHERE Clause", async () => {

test("Parse SQL Query with Multiple WHERE Clauses", () => {
const query = "SELECT id, name FROM student WHERE age = 30 AND name = John";
const parsed = parseQuery(query);
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
isDistinct: false,
joinCondition: null,
joinTable: null,
joinType: null,
limit: null,
groupByFields: null,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
whereClauses: [
{
field: "age",
Expand All @@ -79,9 +97,6 @@ test("Parse SQL Query with Multiple WHERE Clauses", () => {
value: "John",
},
],
joinType: null,
joinCondition: null,
joinTable: null,
});
});

Expand Down
103 changes: 44 additions & 59 deletions tests/step-07/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const readCSV = require("../../src/csvReader");
const { parseQuery } = require("../../src/queryParser");
const executeSELECTQuery = require("../../src/index");
const { readCSV } = require("../../src/csvReader");
const { parseSelectQuery } = require("../../src/queryParser");
const { executeSELECTQuery } = require("../../src/index");

test("Read CSV File", async () => {
const data = await readCSV("./student.csv");
Expand All @@ -10,19 +10,6 @@ test("Read CSV File", async () => {
expect(data[0].age).toBe("30"); //ignore the string type here, we will fix this later
});

test("Parse SQL Query", () => {
const query = "SELECT id, name FROM student";
const parsed = parseQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [],
joinType: null,
joinCondition: null,
joinTable: null,
});
});

test("Execute SQL Query", async () => {
const query = "SELECT id, name FROM student";
const result = await executeSELECTQuery(query);
Expand All @@ -33,25 +20,6 @@ test("Execute SQL Query", async () => {
expect(result[0]).toEqual({ id: "1", name: "John" });
});

test("Parse SQL Query with WHERE Clause", () => {
const query = "SELECT id, name FROM student WHERE age = 25";
const parsed = parseQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [
{
field: "age",
operator: "=",
value: "25",
},
],
joinType: null,
joinCondition: null,
joinTable: null,
});
});

test("Execute SQL Query with WHERE Clause", async () => {
const query = "SELECT id, name FROM student WHERE age = 25";
const result = await executeSELECTQuery(query);
Expand All @@ -61,30 +29,6 @@ test("Execute SQL Query with WHERE Clause", async () => {
expect(result[0].id).toBe("2");
});

test("Parse SQL Query with Multiple WHERE Clauses", () => {
const query = "SELECT id, name FROM student WHERE age = 30 AND name = John";
const parsed = parseQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [
{
field: "age",
operator: "=",
value: "30",
},
{
field: "name",
operator: "=",
value: "John",
},
],
joinType: null,
joinCondition: null,
joinTable: null,
});
});

test("Execute SQL Query with Multiple WHERE Clause", async () => {
const query = "SELECT id, name FROM student WHERE age = 30 AND name = John";
const result = await executeSELECTQuery(query);
Expand All @@ -105,3 +49,44 @@ test("Execute SQL Query with Not Equal to", async () => {
expect(result.length).toEqual(3);
expect(result[0]).toHaveProperty("name");
});
test("Parse SQL Query", () => {
const query = "SELECT id, name FROM student";
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
whereClauses: [],
joinCondition: null,
joinTable: null,
joinType: null,
groupByFields: null,
hasAggregateWithoutGroupBy: false,
orderByFields: null,
limit: null,
isDistinct: false,
});
});

test("Parse SQL Query with WHERE Clause", () => {
const query = "SELECT id, name FROM student WHERE age = 25";
const parsed = parseSelectQuery(query);
expect(parsed).toEqual({
fields: ["id", "name"],
table: "student",
isDistinct: false,
whereClauses: [
{
field: "age",
operator: "=",
value: "25",
},
],
joinCondition: null,
groupByFields: null,
limit: null,
orderByFields: null,
hasAggregateWithoutGroupBy: false,
joinTable: null,
joinType: null,
});
});
Loading

0 comments on commit 9dda478

Please sign in to comment.