Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Berezovsky committed Jul 13, 2020
1 parent 49654b9 commit 634605e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
6 changes: 1 addition & 5 deletions src/endpoints/OAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ export default class OAuth extends Endpoint {
}
);

if (!!response.error) {
throw new BaseError(`Error: ${response.error}`);
} else {
return response.access_token;
}
return response.access_token;
}
});
}
Expand Down
33 changes: 2 additions & 31 deletions tests/endpoints/OAuth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,12 @@ describe("oauth", () => {

expect(response).toEqual("access_token");
});

test("api - without data", async () => {
mockAuth(
"/auth/tokens",
{
access_token: "access_token",
client_id: "client_id",
created_at: "created_at",
id: "id",
scope: "scope",
user_id: "user_id"
},
200,
"post"
);

const response = API_CLIENT.oauth.getToken({
client_secret: "client_secret",
redirect_uri: "redirect_uri",
authorization_code: "authorization_code"
});

expect(() =>
response.then(res => !!res.error && response.toThrowError())
);
});
});

describe("setToken", () => {
test("set Client with new accessToken", () => {
expect(() =>
API_CLIENT.oauth
.setToken("access_token")
.objectContaining("access_token")
);
const client = API_CLIENT.oauth.setToken("accessToken");
expect(client).toEqual(API_CLIENT);
});
});

Expand Down

0 comments on commit 634605e

Please sign in to comment.