Skip to content

Commit

Permalink
add reject support for api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
niftyvictor committed Dec 2, 2024
1 parent d7e054e commit ec36c5b
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions test/webauthn/apis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
app.use(errorHandler());

// passing valid field
let registerOptionsResponse = await new Promise((resolve) =>
let registerOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/register")
.send({
Expand All @@ -76,7 +76,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand Down Expand Up @@ -143,7 +143,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
app.use(errorHandler());

// passing valid field
let registerOptionsResponse = await new Promise((resolve) =>
let registerOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/register")
.send({
Expand All @@ -153,7 +153,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand Down Expand Up @@ -206,15 +206,15 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
app.use(errorHandler());

// passing valid field
let signInOptionsResponse = await new Promise((resolve) =>
let signInOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/signin")
.send({ email: "[email protected]" })
.expect(200)
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand Down Expand Up @@ -272,15 +272,15 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
app.use(errorHandler());

// passing valid field
let signInOptionsResponse = await new Promise((resolve) =>
let signInOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/signin")
.send({ email: "[email protected]" })
.expect(200)
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand Down Expand Up @@ -345,7 +345,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
app.use(errorHandler());

const email = `${Math.random().toString().slice(2)}@supertokens.com`;
let registerOptionsResponse = await new Promise((resolve) =>
let registerOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/register")
.send({
Expand All @@ -355,7 +355,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand All @@ -372,7 +372,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
userNotVerified: false,
});

let signUpResponse = await new Promise((resolve) =>
let signUpResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/signup")
.send({
Expand All @@ -384,7 +384,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand Down Expand Up @@ -442,7 +442,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
app.use(errorHandler());

const email = `${Math.random().toString().slice(2)}@supertokens.com`;
let registerOptionsResponse = await new Promise((resolve) =>
let registerOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/register")
.send({
Expand All @@ -452,23 +452,23 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
})
);
assert(registerOptionsResponse.status === "OK");

let signInOptionsResponse = await new Promise((resolve) =>
let signInOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/signin")
.send({ email })
.expect(200)
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand All @@ -485,7 +485,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
userNotVerified: false,
});

let signUpResponse = await new Promise((resolve) =>
let signUpResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/signup")
.send({
Expand All @@ -497,7 +497,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand All @@ -520,7 +520,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
return { status: "OK", user: signUpResponse.user };
});

let signInResponse = await new Promise((resolve) =>
let signInResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/signin")
.send({
Expand All @@ -532,7 +532,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand Down Expand Up @@ -588,7 +588,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
app.use(errorHandler());

const email = `${Math.random().toString().slice(2)}@supertokens.com`;
let registerOptionsResponse = await new Promise((resolve) =>
let registerOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/register")
.send({
Expand All @@ -598,23 +598,23 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
})
);
assert(registerOptionsResponse.status === "OK");

let signInOptionsResponse = await new Promise((resolve) =>
let signInOptionsResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/options/signin")
.send({ email: email + "wrong" })
.expect(200)
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand All @@ -631,7 +631,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
userNotVerified: false,
});

let signUpResponse = await new Promise((resolve) =>
let signUpResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/signup")
.send({
Expand All @@ -643,7 +643,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand All @@ -666,7 +666,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
return { status: "OK", user: signUpResponse.user };
});

let signInResponse = await new Promise((resolve) =>
let signInResponse = await new Promise((resolve, reject) =>
request(app)
.post("/auth/webauthn/signin")
.send({
Expand All @@ -678,7 +678,7 @@ describe(`apisFunctions: ${printPath("[test/webauthn/apis.test.js]")}`, function
.end((err, res) => {
if (err) {
console.log(err);
resolve(undefined);
reject(err);
} else {
resolve(JSON.parse(res.text));
}
Expand Down

0 comments on commit ec36c5b

Please sign in to comment.