Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
xet-a committed Aug 25, 2024
1 parent b5f4be5 commit 1a657bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
24 changes: 13 additions & 11 deletions backend/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AuthService } from "./auth.service";

describe("AuthService", () => {
let service: AuthService;
let usersService: UsersService;
let jwtService: JwtService;

beforeEach(async () => {
Expand All @@ -17,22 +16,23 @@ describe("AuthService", () => {
{
provide: UsersService,
useValue: {
findOrCreate: jest.fn().mockResolvedValue({ id: '123', nickname: 'testuser' }),
findOrCreate: jest
.fn()
.mockResolvedValue({ id: "123", nickname: "testuser" }),
},
},
{
provide: JwtService,
useValue: {
sign: jest.fn().mockReturnValue('signedToken'),
verify: jest.fn().mockReturnValue({ sub: '123', nickname: 'testuser' }),
sign: jest.fn().mockReturnValue("signedToken"),
verify: jest.fn().mockReturnValue({ sub: "123", nickname: "testuser" }),
},
},
],
}).compile();

service = module.get<AuthService>(AuthService);
jwtService = module.get<JwtService>(JwtService);
usersService = module.get<UsersService>(UsersService);
});

it("should be defined", () => {
Expand All @@ -41,13 +41,13 @@ describe("AuthService", () => {

describe("getNewAccessToken", () => {
it("should generate a new access token using refresh token", async () => {
const newToken = await service.getNewAccessToken('refreshToken');
const newToken = await service.getNewAccessToken("refreshToken");

expect(newToken).toBe('signedToken');
expect(jwtService.verify).toHaveBeenCalledWith('refreshToken');
expect(newToken).toBe("signedToken");
expect(jwtService.verify).toHaveBeenCalledWith("refreshToken");
expect(jwtService.sign).toHaveBeenCalledWith(
{ sub: '123', nickname: 'testuser' },
expect.any(Object),
{ sub: "123", nickname: "testuser" },
expect.any(Object)
);
});

Expand All @@ -56,7 +56,9 @@ describe("AuthService", () => {
throw new Error("Invalid token");
});

await expect(service.getNewAccessToken('invalidToken')).rejects.toThrow("Invalid token");
await expect(service.getNewAccessToken("invalidToken")).rejects.toThrow(
"Invalid token"
);
});
});
});
10 changes: 4 additions & 6 deletions backend/src/auth/jwt-refresh.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import { JwtPayload } from "src/utils/types/jwt.type";
import { AuthorizedUser } from "src/utils/types/req.type";

@Injectable()
export class JwtRefreshStrategy extends PassportStrategy(
PassportJwtStrategy, "refresh"
) {
export class JwtRefreshStrategy extends PassportStrategy(PassportJwtStrategy, "refresh") {
constructor(configService: ConfigService) {
super({
jwtFromRequest: (req: Request) => {
if (req && (req.body as any).refresh_token) {
return (req.body as any).refresh_token;
jwtFromRequest: (req) => {
if (req && req.body.refreshToken) {
return req.body.refreshToken;
}
return null;
},
Expand Down

0 comments on commit 1a657bb

Please sign in to comment.